vim: Add horizontal scrolling support in vim mode (#32558)

Release Notes:

- Added initial support for both `z l` and `z h` in vim mode

These changes relate to #17219 but don't yet close the issue, as this
Pull Request is simply adding support for horizontal scrolling in vim
mode and actually moving the cursor to the correct column in the current
row will be handled in a different Pull Request.

Some notes on these changes:

- 2 new default keybindings added to vim's keymap
    - `z l` which triggers the new `vim::ColumnRight` action
    - `z h` which triggers the new `vim::ColumnLeft` action
- Introduced a new `ScrollAmount` variant, `ScrollAmount::Column(f32)`
to represent horizontal scrolling
- Replaced usage of `em_width` with `em_advance` to actually scroll by
the width of the cursor, instead of the width of the character

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Dino 2025-06-12 23:17:15 -07:00 committed by GitHub
parent f63ae4388d
commit 9a6e8a19b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 60 additions and 11 deletions

View file

@ -669,12 +669,23 @@ impl Editor {
return;
}
let cur_position = self.scroll_position(cx);
let mut current_position = self.scroll_position(cx);
let Some(visible_line_count) = self.visible_line_count() else {
return;
};
let new_pos = cur_position + point(0., amount.lines(visible_line_count));
self.set_scroll_position(new_pos, window, cx);
// If the scroll position is currently at the left edge of the document
// (x == 0.0) and the intent is to scroll right, the gutter's margin
// should first be added to the current position, otherwise the cursor
// will end at the column position minus the margin, which looks off.
if current_position.x == 0.0 && amount.columns() > 0. {
if let Some(last_position_map) = &self.last_position_map {
current_position.x += self.gutter_dimensions.margin / last_position_map.em_advance;
}
}
let new_position =
current_position + point(amount.columns(), amount.lines(visible_line_count));
self.set_scroll_position(new_position, window, cx);
}
/// Returns an ordering. The newest selection is: