vim: Add keybindings for resizing docks (#23874)

Closes #23334

This does not follow the exact way that windows are resized in vim.
Normally the command is `ctrl-w >` however this PR uses just `ctrl->`.
This is because I could not find a good way to read in a count like `10
ctrl-w ctrl->`. This is not really a problem since `ctrl->` can be held
down, which, in my opinion, speeds up resizing. I think this is a good
compromise since it improves usability; however, I am concerned that
this is not intuitive. I am looking forward to feedback.

Release Notes:

- Added the following commands 
  - vim::ResizeLeftDock
  - vim::ResizeRightDock
  - vim::ResizeBottomDock
- Added keybinds
  - `ctrl->` for widening left dock
  - `ctrl-<` for narrowing left dock
This commit is contained in:
AidanV 2025-01-31 20:50:16 -08:00 committed by GitHub
parent a3c7dc3321
commit d0152f9eb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 6 deletions

View file

@ -124,7 +124,7 @@ pub fn init(cx: &mut App) {
workspace.reset_pane_sizes(cx);
});
workspace.register_action(|workspace, _: &MaximizePane, _, cx| {
workspace.register_action(|workspace, _: &MaximizePane, window, cx| {
let pane = workspace.active_pane();
let Some(size) = workspace.bounding_box_for_pane(&pane) else {
return;
@ -138,7 +138,7 @@ pub fn init(cx: &mut App) {
} else {
px(10000.)
};
workspace.resize_pane(Axis::Vertical, desired_size - size.size.height, cx)
workspace.resize_pane(Axis::Vertical, desired_size - size.size.height, window, cx)
});
workspace.register_action(|workspace, action: &ResizePane, window, cx| {
@ -162,7 +162,7 @@ pub fn init(cx: &mut App) {
ResizeIntent::Narrow => (Axis::Horizontal, width.width * -1.),
};
workspace.resize_pane(axis, amount * count, cx);
workspace.resize_pane(axis, amount * count, window, cx);
});
workspace.register_action(|workspace, _: &SearchSubmit, window, cx| {

View file

@ -3240,9 +3240,31 @@ impl Workspace {
}
}
pub fn resize_pane(&mut self, axis: gpui::Axis, amount: Pixels, cx: &mut Context<Self>) {
self.center
.resize(&self.active_pane, axis, amount, &self.bounds);
pub fn resize_pane(
&mut self,
axis: gpui::Axis,
amount: Pixels,
window: &mut Window,
cx: &mut Context<Self>,
) {
let docks = self.all_docks();
let active_dock = docks
.into_iter()
.find(|dock| dock.focus_handle(cx).contains_focused(window, cx));
if let Some(dock) = active_dock {
let Some(panel_size) = dock.read(cx).active_panel_size(window, cx) else {
return;
};
match dock.read(cx).position() {
DockPosition::Left => resize_left_dock(panel_size + amount, self, window, cx),
DockPosition::Bottom => resize_bottom_dock(panel_size + amount, self, window, cx),
DockPosition::Right => resize_right_dock(panel_size + amount, self, window, cx),
}
} else {
self.center
.resize(&self.active_pane, axis, amount, &self.bounds);
}
cx.notify();
}