Add support for resizing panes using vim motions (#21038)

Closes #8628

Release Notes:

- Added support for resizing the current pane using vim keybinds with
the intention to follow the functionality of vim
  - "ctrl-w +" to make a pane taller 
  - "ctrl-w -" to make the pane shorter
  - "ctrl-w >" to make a pane wider
  - "ctrl-w <" to make the pane narrower
- Changed vim pre_count and post_count to globals to allow for other
crates to use the vim count. In this case, it allows for resizing by
more than one unit. For example, "10 ctrl-w -" will decrease the height
of the pane 10 times more than "ctrl-w -"
- This pr does **not** add keybinds for making all panes in an axis
equal size and does **not** add support for resizing docks. This is
mentioned because these could be implied by the original issue

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
AidanV 2024-11-26 16:24:29 -08:00 committed by GitHub
parent d75d34576a
commit f702575255
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 251 additions and 68 deletions

View file

@ -77,17 +77,17 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
Vim::action(editor, cx, |vim, _: &DeleteLeft, cx| {
vim.record_current_action(cx);
let times = vim.take_count(cx);
let times = Vim::take_count(cx);
vim.delete_motion(Motion::Left, times, cx);
});
Vim::action(editor, cx, |vim, _: &DeleteRight, cx| {
vim.record_current_action(cx);
let times = vim.take_count(cx);
let times = Vim::take_count(cx);
vim.delete_motion(Motion::Right, times, cx);
});
Vim::action(editor, cx, |vim, _: &ChangeToEndOfLine, cx| {
vim.start_recording(cx);
let times = vim.take_count(cx);
let times = Vim::take_count(cx);
vim.change_motion(
Motion::EndOfLine {
display_lines: false,
@ -98,7 +98,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
});
Vim::action(editor, cx, |vim, _: &DeleteToEndOfLine, cx| {
vim.record_current_action(cx);
let times = vim.take_count(cx);
let times = Vim::take_count(cx);
vim.delete_motion(
Motion::EndOfLine {
display_lines: false,
@ -109,7 +109,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
});
Vim::action(editor, cx, |vim, _: &JoinLines, cx| {
vim.record_current_action(cx);
let mut times = vim.take_count(cx).unwrap_or(1);
let mut times = Vim::take_count(cx).unwrap_or(1);
if vim.mode.is_visual() {
times = 1;
} else if times > 1 {
@ -130,7 +130,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
});
Vim::action(editor, cx, |vim, _: &Undo, cx| {
let times = vim.take_count(cx);
let times = Vim::take_count(cx);
vim.update_editor(cx, |_, editor, cx| {
for _ in 0..times.unwrap_or(1) {
editor.undo(&editor::actions::Undo, cx);
@ -138,7 +138,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
});
});
Vim::action(editor, cx, |vim, _: &Redo, cx| {
let times = vim.take_count(cx);
let times = Vim::take_count(cx);
vim.update_editor(cx, |_, editor, cx| {
for _ in 0..times.unwrap_or(1) {
editor.redo(&editor::actions::Redo, cx);
@ -396,7 +396,7 @@ impl Vim {
}
fn yank_line(&mut self, _: &YankLine, cx: &mut ViewContext<Self>) {
let count = self.take_count(cx);
let count = Vim::take_count(cx);
self.yank_motion(motion::Motion::CurrentLine, count, cx)
}
@ -416,7 +416,7 @@ impl Vim {
}
pub(crate) fn normal_replace(&mut self, text: Arc<str>, cx: &mut ViewContext<Self>) {
let count = self.take_count(cx).unwrap_or(1);
let count = Vim::take_count(cx).unwrap_or(1);
self.stop_recording(cx);
self.update_editor(cx, |_, editor, cx| {
editor.transact(cx, |editor, cx| {