From 43d682f6b887ea80260c9d9591fcecbc0100774d Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 20 Oct 2023 12:46:14 -0600 Subject: [PATCH] Handle pixel-down to last line when no trailing newline --- crates/editor/src/display_map.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 184990ea78dc759fa8e1d24f6ae57ac58cc0685c..1d6deb910aa8d55d8f780cdfd8ce169662cfc940 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -574,6 +574,7 @@ impl DisplaySnapshot { ) -> Line { let mut styles = Vec::new(); let mut line = String::new(); + let mut ended_in_newline = false; let range = display_row..display_row + 1; for chunk in self.highlighted_chunks(range, false, editor_style) { @@ -589,6 +590,7 @@ impl DisplaySnapshot { } else { Cow::Borrowed(&editor_style.text) }; + ended_in_newline = chunk.chunk.ends_with("\n"); styles.push(( chunk.chunk.len(), @@ -600,6 +602,22 @@ impl DisplaySnapshot { )); } + // our pixel positioning logic assumes each line ends in \n, + // this is almost always true except for the last line which + // may have no trailing newline. + if !ended_in_newline && display_row == self.max_point().row() { + line.push_str("\n"); + + styles.push(( + "\n".len(), + RunStyle { + font_id: editor_style.text.font_id, + color: editor_style.text_color, + underline: editor_style.text.underline, + }, + )); + } + text_layout_cache.layout_str(&line, editor_style.text.font_size, &styles) }