editor: Use em_advance everywhere for horizontal scroll position computations (#33514)

Closes #33472

This PR fixes some regressions that were introduced in
https://github.com/zed-industries/zed/pull/32558, which updated the
editor scrolling to use `em_advance` instead of `em_width` for the
horizontal scroll position calculation.
However, not all occurrences were updated, which caused issues with wrap
guides and some small stuttering with horizontal autoscroll whilst
typing/navigating with the keyboard.

Release Notes:

- Fixed an issue where horizontal autoscrolling would stutter and indent
guides would drift when scrolling horizontally.
This commit is contained in:
Finn Evers 2025-06-27 11:32:50 +02:00 committed by GitHub
parent e6bc1308af
commit 4c2415b338
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 18 deletions

View file

@ -5238,8 +5238,8 @@ impl EditorElement {
paint_highlight(range.start, range.end, color, edges);
}
let scroll_left =
layout.position_map.snapshot.scroll_position().x * layout.position_map.em_width;
let scroll_left = layout.position_map.snapshot.scroll_position().x
* layout.position_map.em_advance;
for (wrap_position, active) in layout.wrap_guides.iter() {
let x = (layout.position_map.text_hitbox.origin.x
@ -6676,7 +6676,7 @@ impl EditorElement {
let position_map: &PositionMap = &position_map;
let line_height = position_map.line_height;
let max_glyph_width = position_map.em_width;
let max_glyph_advance = position_map.em_advance;
let (delta, axis) = match delta {
gpui::ScrollDelta::Pixels(mut pixels) => {
//Trackpad
@ -6687,15 +6687,15 @@ impl EditorElement {
gpui::ScrollDelta::Lines(lines) => {
//Not trackpad
let pixels =
point(lines.x * max_glyph_width, lines.y * line_height);
point(lines.x * max_glyph_advance, lines.y * line_height);
(pixels, None)
}
};
let current_scroll_position = position_map.snapshot.scroll_position();
let x = (current_scroll_position.x * max_glyph_width
let x = (current_scroll_position.x * max_glyph_advance
- (delta.x * scroll_sensitivity))
/ max_glyph_width;
/ max_glyph_advance;
let y = (current_scroll_position.y * line_height
- (delta.y * scroll_sensitivity))
/ line_height;
@ -8591,7 +8591,7 @@ impl Element for EditorElement {
start_row,
editor_content_width,
scroll_width,
em_width,
em_advance,
&line_layouts,
cx,
)