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

@ -7739,8 +7739,7 @@ impl Element for EditorElement {
let line_height = style.text.line_height_in_pixels(window.rem_size());
let em_width = window.text_system().em_width(font_id, font_size).unwrap();
let em_advance = window.text_system().em_advance(font_id, font_size).unwrap();
let glyph_grid_cell = size(em_width, line_height);
let glyph_grid_cell = size(em_advance, line_height);
let gutter_dimensions = snapshot
.gutter_dimensions(
@ -8299,7 +8298,7 @@ impl Element for EditorElement {
MultiBufferRow(end_anchor.to_point(&snapshot.buffer_snapshot).row);
let scroll_max = point(
((scroll_width - editor_content_width) / em_width).max(0.0),
((scroll_width - editor_content_width) / em_advance).max(0.0),
max_scroll_top,
);
@ -8311,7 +8310,7 @@ impl Element for EditorElement {
start_row,
editor_content_width,
scroll_width,
em_width,
em_advance,
&line_layouts,
cx,
)
@ -8326,10 +8325,9 @@ impl Element for EditorElement {
});
let scroll_pixel_position = point(
scroll_position.x * em_width,
scroll_position.x * em_advance,
scroll_position.y * line_height,
);
let indent_guides = self.layout_indent_guides(
content_origin,
text_hitbox.origin,
@ -9454,7 +9452,7 @@ impl PositionMap {
let scroll_position = self.snapshot.scroll_position();
let position = position - text_bounds.origin;
let y = position.y.max(px(0.)).min(self.size.height);
let x = position.x + (scroll_position.x * self.em_width);
let x = position.x + (scroll_position.x * self.em_advance);
let row = ((y / self.line_height) + scroll_position.y) as u32;
let (column, x_overshoot_after_line_end) = if let Some(line) = self