Use split direction preferences more (#16679)

Use new split direction preferences in more places (#16345)

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-08-22 11:13:33 -06:00 committed by GitHub
parent 93642c9c51
commit c697eaba82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 54 additions and 41 deletions

View File

@ -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",

View File

@ -298,7 +298,8 @@ pub fn init(cx: &mut AppContext) {
cx.observe_new_views(
|workspace: &mut Workspace, _cx: &mut ViewContext<Workspace>| {
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<Workspace>,
) {
Self::new_file_in_direction(workspace, SplitDirection::vertical(cx), cx)
}
fn new_file_horizontal(
workspace: &mut Workspace,
_: &workspace::NewFileSplitHorizontal,
cx: &mut ViewContext<Workspace>,
) {
Self::new_file_in_direction(workspace, SplitDirection::horizontal(cx), cx)
}
fn new_file_in_direction(
workspace: &mut Workspace,
direction: SplitDirection,
cx: &mut ViewContext<Workspace>,
) {
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?;

View File

@ -546,14 +546,8 @@ fn generate_commands(_: &AppContext) -> Vec<VimCommand> {
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(),

View File

@ -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)),

View File

@ -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>) -> Pixels {
match self {
Self::Up => rect.origin.y,

View File

@ -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,