From 8bef4800f0f04da68bbade0e0d18b2a5b6c5f2a7 Mon Sep 17 00:00:00 2001 From: Rian Drake Date: Tue, 21 Oct 2025 04:01:26 +1300 Subject: [PATCH] workspace: Add NewFileSplit action with direction (#39726) Add new `workspace::NewFileSplit` action which expects a `SplitDirection` argument, allowing users to programmatically control the direction of the split in keymaps, for example: ```json { "context": "Editor", "bindings": { "ctrl-s ctrl-h": ["workspace::NewFileSplit", "left"], "ctrl-s ctrl-j": ["workspace::NewFileSplit", "down"], "ctrl-s ctrl-k": ["workspace::NewFileSplit", "up"], "ctrl-s ctrl-l": ["workspace::NewFileSplit", "right"] } } ``` Release Notes: - Added `workspace::NewFileSplit` action, which can be used to programmatically split the editor in the provided direction. Co-authored-by: Rian Drake Co-authored-by: dino --- crates/editor/src/editor.rs | 10 ++++++++++ crates/workspace/src/workspace.rs | 6 ++++++ crates/zed/src/zed.rs | 1 + 3 files changed, 17 insertions(+) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 3b2e30a1761af381c4a3a52e660f8d26dc043ce8..7e633a40e6525668d76ab95d2163a615c296a6e0 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -358,6 +358,7 @@ pub fn init(cx: &mut App) { cx.observe_new( |workspace: &mut Workspace, _: Option<&mut Window>, _cx: &mut Context| { workspace.register_action(Editor::new_file); + workspace.register_action(Editor::new_file_split); workspace.register_action(Editor::new_file_vertical); workspace.register_action(Editor::new_file_horizontal); workspace.register_action(Editor::cancel_language_server_work); @@ -2683,6 +2684,15 @@ impl Editor { Self::new_file_in_direction(workspace, SplitDirection::horizontal(cx), window, cx) } + fn new_file_split( + workspace: &mut Workspace, + action: &workspace::NewFileSplit, + window: &mut Window, + cx: &mut Context, + ) { + Self::new_file_in_direction(workspace, action.0, window, cx) + } + fn new_file_in_direction( workspace: &mut Workspace, direction: SplitDirection, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 053b578ff9082bd933440a36abab47c9b84928bd..85a17c244bebe5d3c33d1bda1fe4ae5758038e56 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -302,6 +302,12 @@ pub struct MoveItemToPaneInDirection { pub clone: bool, } +/// Creates a new file in a split of the desired direction. +#[derive(Clone, Deserialize, PartialEq, JsonSchema, Action)] +#[action(namespace = workspace)] +#[serde(deny_unknown_fields)] +pub struct NewFileSplit(pub SplitDirection); + fn default_right() -> SplitDirection { SplitDirection::Right } diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 4a57939c407ee21bed48e12f7af2c44c6d51a1db..e2116415d4b882b66728c43cee90b251b3448013 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -4563,6 +4563,7 @@ mod tests { | "workspace::ActivatePane" | "workspace::MoveItemToPane" | "workspace::MoveItemToPaneInDirection" + | "workspace::NewFileSplit" | "workspace::OpenTerminal" | "workspace::SendKeystrokes" | "agent::NewNativeAgentThreadFromSummary"