workspace: Move panes to span the entire border in Vim mode (#39123)

Currently, <kbd>⌃w</kbd> + <kbd>HJKL</kbd> keystrokes swap active pane
with another pane in that direction. Also, if there is no pane to swap
with, nothing happens.

This does not match the expected Vim behavior: moving the split to span
the entire border.

See
https://github.com/vim/vim/blob/ca6a260ef1a4b4ae94bc71c17cbabf8f12bf0f8c/runtime/doc/windows.txt#L527-L549

This change adds `MovePane{Up,Down,Left,Right}` actions that do exactly
that and updates default Vim keymap.

<table>
<tr>
  <th>Before</th>
  <th>After</th>
<tr>
<td><video
src="https://github.com/user-attachments/assets/5d3a25bf-e8b6-46c1-9fbb-004f0194e0dd">
<td><video
src="https://github.com/user-attachments/assets/5276f115-5063-411e-b141-5d268a79581b">
<tr>
  <th>Vim</th>
<tr>
<td><video
src="https://github.com/user-attachments/assets/df9fbf83-d0de-42c0-8fb0-b134be833bde">
</table>

Release Notes:

- Changed `ctrl+w` + `shift-[hjkl]` in Vim mode to move the split to
span the entire border, aligning with Vim‘s behavior.

Signed-off-by: Ivan Trubach <mr.trubach@icloud.com>
This commit is contained in:
Ivan Trubach
2025-10-16 17:09:04 -06:00
committed by GitHub
parent 620df0c722
commit aec3c2fbb7
4 changed files with 130 additions and 10 deletions
+25 -3
View File
@@ -29,9 +29,9 @@ use util::{ResultExt, TryFutureExt};
use workspace::{
ActivateNextPane, ActivatePane, ActivatePaneDown, ActivatePaneLeft, ActivatePaneRight,
ActivatePaneUp, ActivatePreviousPane, DraggedSelection, DraggedTab, ItemId, MoveItemToPane,
MoveItemToPaneInDirection, NewTerminal, Pane, PaneGroup, SplitDirection, SplitDown, SplitLeft,
SplitRight, SplitUp, SwapPaneDown, SwapPaneLeft, SwapPaneRight, SwapPaneUp, ToggleZoom,
Workspace,
MoveItemToPaneInDirection, MovePaneDown, MovePaneLeft, MovePaneRight, MovePaneUp, NewTerminal,
Pane, PaneGroup, SplitDirection, SplitDown, SplitLeft, SplitRight, SplitUp, SwapPaneDown,
SwapPaneLeft, SwapPaneRight, SwapPaneUp, ToggleZoom, Workspace,
dock::{DockPosition, Panel, PanelEvent, PanelHandle},
item::SerializableItem,
move_active_item, move_item, pane,
@@ -1055,6 +1055,16 @@ impl TerminalPanel {
cx.notify();
}
}
fn move_pane_to_border(&mut self, direction: SplitDirection, cx: &mut Context<Self>) {
if self
.center
.move_to_border(&self.active_pane, direction)
.unwrap()
{
cx.notify();
}
}
}
fn is_enabled_in_workspace(workspace: &Workspace, cx: &App) -> bool {
@@ -1404,6 +1414,18 @@ impl Render for TerminalPanel {
.on_action(cx.listener(|terminal_panel, _: &SwapPaneDown, _, cx| {
terminal_panel.swap_pane_in_direction(SplitDirection::Down, cx);
}))
.on_action(cx.listener(|terminal_panel, _: &MovePaneLeft, _, cx| {
terminal_panel.move_pane_to_border(SplitDirection::Left, cx);
}))
.on_action(cx.listener(|terminal_panel, _: &MovePaneRight, _, cx| {
terminal_panel.move_pane_to_border(SplitDirection::Right, cx);
}))
.on_action(cx.listener(|terminal_panel, _: &MovePaneUp, _, cx| {
terminal_panel.move_pane_to_border(SplitDirection::Up, cx);
}))
.on_action(cx.listener(|terminal_panel, _: &MovePaneDown, _, cx| {
terminal_panel.move_pane_to_border(SplitDirection::Down, cx);
}))
.on_action(
cx.listener(|terminal_panel, action: &MoveItemToPane, window, cx| {
let Some(&target_pane) =