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

@ -118,7 +118,7 @@ impl Vim {
{
self.record_current_action(cx);
self.store_visual_marks(cx);
let count = self.take_count(cx).unwrap_or(1) as u32;
let count = Vim::take_count(cx).unwrap_or(1) as u32;
self.update_editor(cx, |vim, editor, cx| {
let mut ranges = Vec::new();

View file

@ -26,13 +26,13 @@ impl_actions!(vim, [Increment, Decrement]);
pub fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
Vim::action(editor, cx, |vim, action: &Increment, cx| {
vim.record_current_action(cx);
let count = vim.take_count(cx).unwrap_or(1);
let count = Vim::take_count(cx).unwrap_or(1);
let step = if action.step { 1 } else { 0 };
vim.increment(count as i64, step, cx)
});
Vim::action(editor, cx, |vim, action: &Decrement, cx| {
vim.record_current_action(cx);
let count = vim.take_count(cx).unwrap_or(1);
let count = Vim::take_count(cx).unwrap_or(1);
let step = if action.step { -1 } else { 0 };
vim.increment(-(count as i64), step, cx)
});

View file

@ -25,7 +25,7 @@ impl Vim {
pub fn paste(&mut self, action: &Paste, cx: &mut ViewContext<Self>) {
self.record_current_action(cx);
self.store_visual_marks(cx);
let count = self.take_count(cx).unwrap_or(1);
let count = Vim::take_count(cx).unwrap_or(1);
self.update_editor(cx, |vim, editor, cx| {
let text_layout_details = editor.text_layout_details(cx);

View file

@ -158,7 +158,7 @@ impl Vim {
}
pub(crate) fn replay_register(&mut self, mut register: char, cx: &mut ViewContext<Self>) {
let mut count = self.take_count(cx).unwrap_or(1);
let mut count = Vim::take_count(cx).unwrap_or(1);
self.clear_operator(cx);
let globals = Vim::globals(cx);
@ -184,7 +184,7 @@ impl Vim {
}
pub(crate) fn repeat(&mut self, from_insert_mode: bool, cx: &mut ViewContext<Self>) {
let count = self.take_count(cx);
let count = Vim::take_count(cx);
let Some((mut actions, selection, mode)) = Vim::update_globals(cx, |globals, _| {
let actions = globals.recorded_actions.clone();
if actions.is_empty() {

View file

@ -53,7 +53,7 @@ impl Vim {
cx: &mut ViewContext<Self>,
by: fn(c: Option<f32>) -> ScrollAmount,
) {
let amount = by(self.take_count(cx).map(|c| c as f32));
let amount = by(Vim::take_count(cx).map(|c| c as f32));
self.update_editor(cx, |_, editor, cx| {
scroll_editor(editor, move_cursor, &amount, cx)
});

View file

@ -120,7 +120,7 @@ impl Vim {
} else {
Direction::Next
};
let count = self.take_count(cx).unwrap_or(1);
let count = Vim::take_count(cx).unwrap_or(1);
let prior_selections = self.editor_selections(cx);
pane.update(cx, |pane, cx| {
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
@ -226,7 +226,7 @@ impl Vim {
pub fn move_to_match_internal(&mut self, direction: Direction, cx: &mut ViewContext<Self>) {
let Some(pane) = self.pane(cx) else { return };
let count = self.take_count(cx).unwrap_or(1);
let count = Vim::take_count(cx).unwrap_or(1);
let prior_selections = self.editor_selections(cx);
let success = pane.update(cx, |pane, cx| {
@ -264,7 +264,7 @@ impl Vim {
cx: &mut ViewContext<Self>,
) {
let Some(pane) = self.pane(cx) else { return };
let count = self.take_count(cx).unwrap_or(1);
let count = Vim::take_count(cx).unwrap_or(1);
let prior_selections = self.editor_selections(cx);
let vim = cx.view().clone();

View file

@ -9,7 +9,7 @@ actions!(vim, [Substitute, SubstituteLine]);
pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
Vim::action(editor, cx, |vim, _: &Substitute, cx| {
vim.start_recording(cx);
let count = vim.take_count(cx);
let count = Vim::take_count(cx);
vim.substitute(count, vim.mode == Mode::VisualLine, cx);
});
@ -18,7 +18,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
if matches!(vim.mode, Mode::VisualBlock | Mode::Visual) {
vim.switch_mode(Mode::VisualLine, false, cx)
}
let count = vim.take_count(cx);
let count = Vim::take_count(cx);
vim.substitute(count, true, cx)
});
}