From c697eaba829b9122e8bcd6bab376677b024e78c6 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 22 Aug 2024 11:13:33 -0600 Subject: [PATCH] Use split direction preferences more (#16679) Use new split direction preferences in more places (#16345) Release Notes: - N/A --- assets/keymaps/vim.json | 14 +++++++------- crates/editor/src/editor.rs | 24 ++++++++++++++++++++---- crates/vim/src/command.rs | 10 ++-------- crates/workspace/src/pane.rs | 20 +++----------------- crates/workspace/src/pane_group.rs | 21 ++++++++++++++++++++- crates/workspace/src/workspace.rs | 6 ++---- 6 files changed, 54 insertions(+), 41 deletions(-) diff --git a/assets/keymaps/vim.json b/assets/keymaps/vim.json index 388ba5e8ab..9e6dfdb720 100644 --- a/assets/keymaps/vim.json +++ b/assets/keymaps/vim.json @@ -177,19 +177,19 @@ "ctrl-w ctrl-p": "workspace::ActivatePreviousPane", "ctrl-w shift-w": "workspace::ActivatePreviousPane", "ctrl-w ctrl-shift-w": "workspace::ActivatePreviousPane", - "ctrl-w v": "pane::SplitLeft", - "ctrl-w ctrl-v": "pane::SplitLeft", - "ctrl-w s": "pane::SplitUp", - "ctrl-w shift-s": "pane::SplitUp", - "ctrl-w ctrl-s": "pane::SplitUp", + "ctrl-w v": "pane::SplitVertical", + "ctrl-w ctrl-v": "pane::SplitVertical", + "ctrl-w s": "pane::SplitHorizontal", + "ctrl-w shift-s": "pane::SplitHorizontal", + "ctrl-w ctrl-s": "pane::SplitHorizontal", "ctrl-w c": "pane::CloseAllItems", "ctrl-w ctrl-c": "pane::CloseAllItems", "ctrl-w q": "pane::CloseAllItems", "ctrl-w ctrl-q": "pane::CloseAllItems", "ctrl-w o": "workspace::CloseInactiveTabsAndPanes", "ctrl-w ctrl-o": "workspace::CloseInactiveTabsAndPanes", - "ctrl-w n": ["workspace::NewFileInDirection", "Up"], - "ctrl-w ctrl-n": ["workspace::NewFileInDirection", "Up"], + "ctrl-w n": "workspace::NewFileSplitHorizontal", + "ctrl-w ctrl-n": "workspace::NewFileSplitHorizontal", "ctrl-w d": "editor::GoToDefinitionSplit", "ctrl-w g d": "editor::GoToDefinitionSplit", "ctrl-w shift-d": "editor::GoToTypeDefinitionSplit", diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 4b19ae7e2c..32c8075af5 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -298,7 +298,8 @@ pub fn init(cx: &mut AppContext) { cx.observe_new_views( |workspace: &mut Workspace, _cx: &mut ViewContext| { workspace.register_action(Editor::new_file); - workspace.register_action(Editor::new_file_in_direction); + workspace.register_action(Editor::new_file_vertical); + workspace.register_action(Editor::new_file_horizontal); }, ) .detach(); @@ -2068,14 +2069,29 @@ impl Editor { }) } - pub fn new_file_in_direction( + fn new_file_vertical( workspace: &mut Workspace, - action: &workspace::NewFileInDirection, + _: &workspace::NewFileSplitVertical, + cx: &mut ViewContext, + ) { + Self::new_file_in_direction(workspace, SplitDirection::vertical(cx), cx) + } + + fn new_file_horizontal( + workspace: &mut Workspace, + _: &workspace::NewFileSplitHorizontal, + cx: &mut ViewContext, + ) { + Self::new_file_in_direction(workspace, SplitDirection::horizontal(cx), cx) + } + + fn new_file_in_direction( + workspace: &mut Workspace, + direction: SplitDirection, cx: &mut ViewContext, ) { let project = workspace.project().clone(); let create = project.update(cx, |project, cx| project.create_buffer(cx)); - let direction = action.0; cx.spawn(|workspace, mut cx| async move { let buffer = create.await?; diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rs index b642879428..0ed1f0e1d9 100644 --- a/crates/vim/src/command.rs +++ b/crates/vim/src/command.rs @@ -546,14 +546,8 @@ fn generate_commands(_: &AppContext) -> Vec { VimCommand::new(("bf", "irst"), workspace::ActivateItem(0)), VimCommand::new(("br", "ewind"), workspace::ActivateItem(0)), VimCommand::new(("bl", "ast"), workspace::ActivateLastItem), - VimCommand::new( - ("new", ""), - workspace::NewFileInDirection(workspace::SplitDirection::Up), - ), - VimCommand::new( - ("vne", "w"), - workspace::NewFileInDirection(workspace::SplitDirection::Left), - ), + VimCommand::new(("new", ""), workspace::NewFileSplitHorizontal), + VimCommand::new(("vne", "w"), workspace::NewFileSplitVertical), VimCommand::new(("tabe", "dit"), workspace::NewFile), VimCommand::new(("tabnew", ""), workspace::NewFile), VimCommand::new(("tabn", "ext"), workspace::ActivateNextItem).count(), diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index cc00ab9f61..92a245e836 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -5,10 +5,7 @@ use crate::{ }, notifications::NotifyResultExt, toolbar::Toolbar, - workspace_settings::{ - AutosaveSetting, PaneSplitDirectionHorizontal, PaneSplitDirectionVertical, TabBarSettings, - WorkspaceSettings, - }, + workspace_settings::{AutosaveSetting, TabBarSettings, WorkspaceSettings}, CloseWindow, CopyPath, CopyRelativePath, NewFile, NewTerminal, OpenInTerminal, OpenTerminal, OpenVisible, SplitDirection, ToggleFileFinder, ToggleProjectSymbols, ToggleZoom, Workspace, }; @@ -2251,21 +2248,10 @@ impl Render for Pane { .on_action(cx.listener(|pane, _: &SplitLeft, cx| pane.split(SplitDirection::Left, cx))) .on_action(cx.listener(|pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx))) .on_action(cx.listener(|pane, _: &SplitHorizontal, cx| { - let split_direction = - WorkspaceSettings::get(None, cx).pane_split_direction_horizontal; - match split_direction { - PaneSplitDirectionHorizontal::Down => pane.split(SplitDirection::Down, cx), - _ => pane.split(SplitDirection::Up, cx), - } + pane.split(SplitDirection::horizontal(cx), cx) })) .on_action(cx.listener(|pane, _: &SplitVertical, cx| { - let split_direction = - WorkspaceSettings::get(None, cx).pane_split_direction_vertical; - - match split_direction { - PaneSplitDirectionVertical::Right => pane.split(SplitDirection::Right, cx), - _ => pane.split(SplitDirection::Left, cx), - } + pane.split(SplitDirection::vertical(cx), cx) })) .on_action( cx.listener(|pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx)), diff --git a/crates/workspace/src/pane_group.rs b/crates/workspace/src/pane_group.rs index adc187fbd1..dd26497363 100644 --- a/crates/workspace/src/pane_group.rs +++ b/crates/workspace/src/pane_group.rs @@ -1,4 +1,8 @@ -use crate::{pane_group::element::pane_axis, AppState, FollowerState, Pane, Workspace}; +use crate::{ + pane_group::element::pane_axis, + workspace_settings::{PaneSplitDirectionHorizontal, PaneSplitDirectionVertical}, + AppState, FollowerState, Pane, Workspace, WorkspaceSettings, +}; use anyhow::{anyhow, Result}; use call::{ActiveCall, ParticipantLocation}; use client::proto::PeerId; @@ -10,6 +14,7 @@ use gpui::{ use parking_lot::Mutex; use project::Project; use serde::Deserialize; +use settings::Settings; use std::sync::Arc; use ui::prelude::*; @@ -561,6 +566,20 @@ impl SplitDirection { [Self::Up, Self::Down, Self::Left, Self::Right] } + pub fn vertical(cx: &WindowContext) -> Self { + match WorkspaceSettings::get_global(cx).pane_split_direction_vertical { + PaneSplitDirectionVertical::Left => SplitDirection::Left, + PaneSplitDirectionVertical::Right => SplitDirection::Right, + } + } + + pub fn horizontal(cx: &WindowContext) -> Self { + match WorkspaceSettings::get_global(cx).pane_split_direction_horizontal { + PaneSplitDirectionHorizontal::Down => SplitDirection::Down, + PaneSplitDirectionHorizontal::Up => SplitDirection::Up, + } + } + pub fn edge(&self, rect: Bounds) -> Pixels { match self { Self::Up => rect.origin.y, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index d2be56fa4b..850f428c4b 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -136,6 +136,8 @@ actions!( FollowNextCollaborator, NewCenterTerminal, NewFile, + NewFileSplitVertical, + NewFileSplitHorizontal, NewSearch, NewTerminal, NewWindow, @@ -168,9 +170,6 @@ pub struct ActivatePaneInDirection(pub SplitDirection); #[derive(Clone, Deserialize, PartialEq)] pub struct SwapPaneInDirection(pub SplitDirection); -#[derive(Clone, Deserialize, PartialEq)] -pub struct NewFileInDirection(pub SplitDirection); - #[derive(Clone, PartialEq, Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SaveAll { @@ -220,7 +219,6 @@ impl_actions!( ActivatePaneInDirection, CloseAllItemsAndPanes, CloseInactiveTabsAndPanes, - NewFileInDirection, OpenTerminal, Reload, Save,