Skip to content

Commit 8bef480

Browse files
riandrakewerkz-by-drakedinocosta
authored
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 <[email protected]> Co-authored-by: dino <[email protected]>
1 parent 67b9d48 commit 8bef480

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

crates/editor/src/editor.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ pub fn init(cx: &mut App) {
358358
cx.observe_new(
359359
|workspace: &mut Workspace, _: Option<&mut Window>, _cx: &mut Context<Workspace>| {
360360
workspace.register_action(Editor::new_file);
361+
workspace.register_action(Editor::new_file_split);
361362
workspace.register_action(Editor::new_file_vertical);
362363
workspace.register_action(Editor::new_file_horizontal);
363364
workspace.register_action(Editor::cancel_language_server_work);
@@ -2683,6 +2684,15 @@ impl Editor {
26832684
Self::new_file_in_direction(workspace, SplitDirection::horizontal(cx), window, cx)
26842685
}
26852686

2687+
fn new_file_split(
2688+
workspace: &mut Workspace,
2689+
action: &workspace::NewFileSplit,
2690+
window: &mut Window,
2691+
cx: &mut Context<Workspace>,
2692+
) {
2693+
Self::new_file_in_direction(workspace, action.0, window, cx)
2694+
}
2695+
26862696
fn new_file_in_direction(
26872697
workspace: &mut Workspace,
26882698
direction: SplitDirection,

crates/workspace/src/workspace.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ pub struct MoveItemToPaneInDirection {
302302
pub clone: bool,
303303
}
304304

305+
/// Creates a new file in a split of the desired direction.
306+
#[derive(Clone, Deserialize, PartialEq, JsonSchema, Action)]
307+
#[action(namespace = workspace)]
308+
#[serde(deny_unknown_fields)]
309+
pub struct NewFileSplit(pub SplitDirection);
310+
305311
fn default_right() -> SplitDirection {
306312
SplitDirection::Right
307313
}

crates/zed/src/zed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,6 +4563,7 @@ mod tests {
45634563
| "workspace::ActivatePane"
45644564
| "workspace::MoveItemToPane"
45654565
| "workspace::MoveItemToPaneInDirection"
4566+
| "workspace::NewFileSplit"
45664567
| "workspace::OpenTerminal"
45674568
| "workspace::SendKeystrokes"
45684569
| "agent::NewNativeAgentThreadFromSummary"

0 commit comments

Comments
 (0)