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 <rian.drake@rocketwerkz.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
This commit is contained in:
co-authored by
Rian Drake
dino
parent
67b9d480b4
commit
8bef4800f0
@@ -358,6 +358,7 @@ pub fn init(cx: &mut App) {
|
||||
cx.observe_new(
|
||||
|workspace: &mut Workspace, _: Option<&mut Window>, _cx: &mut Context<Workspace>| {
|
||||
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<Workspace>,
|
||||
) {
|
||||
Self::new_file_in_direction(workspace, action.0, window, cx)
|
||||
}
|
||||
|
||||
fn new_file_in_direction(
|
||||
workspace: &mut Workspace,
|
||||
direction: SplitDirection,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -4563,6 +4563,7 @@ mod tests {
|
||||
| "workspace::ActivatePane"
|
||||
| "workspace::MoveItemToPane"
|
||||
| "workspace::MoveItemToPaneInDirection"
|
||||
| "workspace::NewFileSplit"
|
||||
| "workspace::OpenTerminal"
|
||||
| "workspace::SendKeystrokes"
|
||||
| "agent::NewNativeAgentThreadFromSummary"
|
||||
|
||||
Reference in New Issue
Block a user