From 7c03e11cfc813467fd3241aece7f30b7ff511764 Mon Sep 17 00:00:00 2001 From: Aaron Feickert <66188213+AaronFeickert@users.noreply.github.com> Date: Fri, 20 Dec 2024 04:26:27 -0600 Subject: [PATCH] Fix blank line cursor width (#22275) This PR ensures that, for fixed-width fonts, the cursor width is the same on blank lines as on non-blank lines, as well as at the end of a line. It does so by using the em advance to define the cursor width instead of the em width in these cases. Note that this can look... bizarre on non-fixed-width fonts: Screenshot 2024-12-19 at 21 43 11 However, this is arguably reasonably consistent with how (terminal) Vim handles it: Screenshot 2024-12-19 at 21 46 42 Closes #22260. Release Notes: - N/A --- crates/editor/src/element.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 69ee6a74eaa7efa5e9804145e81129826228ef3d..537ab003531c162390361edbe64c8181e1b33bec 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1032,6 +1032,7 @@ impl EditorElement { scroll_pixel_position: gpui::Point, line_height: Pixels, em_width: Pixels, + em_advance: Pixels, autoscroll_containing_element: bool, cx: &mut WindowContext, ) -> Vec { @@ -1058,7 +1059,7 @@ impl EditorElement { let mut block_width = cursor_row_layout.x_for_index(cursor_column + 1) - cursor_character_x; if block_width == Pixels::ZERO { - block_width = em_width; + block_width = em_advance; } let block_text = if let CursorShape::Block = selection.cursor_shape { snapshot @@ -6246,6 +6247,7 @@ impl Element for EditorElement { scroll_pixel_position, line_height, em_width, + em_advance, autoscroll_containing_element, cx, );