From d273fa6dd0bf063765318582c61d4120a0b211d6 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 8 Nov 2023 13:52:42 -0800 Subject: [PATCH] Fix DisplaySnapshot::x_for_point always returning 0 Co-authored-by: Marshall --- crates/editor2/src/display_map.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/editor2/src/display_map.rs b/crates/editor2/src/display_map.rs index 808f0d340a4807b64732c85ef6eb258def3c7f12..f808ffa7026f496faa0429b6fa7f8af1468e2bcc 100644 --- a/crates/editor2/src/display_map.rs +++ b/crates/editor2/src/display_map.rs @@ -572,7 +572,6 @@ impl DisplaySnapshot { ) -> Line { let mut runs = 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) { @@ -588,17 +587,18 @@ impl DisplaySnapshot { } else { Cow::Borrowed(&editor_style.text) }; - ended_in_newline = chunk.chunk.ends_with("\n"); runs.push(text_style.to_run(chunk.chunk.len())) } - // 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"); - runs.push(editor_style.text.to_run("\n".len())); + if line.ends_with('\n') { + line.pop(); + if let Some(last_run) = runs.last_mut() { + last_run.len -= 1; + if last_run.len == 0 { + runs.pop(); + } + } } let font_size = editor_style.text.font_size.to_pixels(*rem_size);