From 3310dc79db2470e47e1295505cf8c870d1b7e566 Mon Sep 17 00:00:00 2001 From: Zero <46195892+Atreyagaurav@users.noreply.github.com> Date: Fri, 16 May 2025 17:26:14 -0400 Subject: [PATCH] Fix `text_editor` syntax highlighting on paste Fixes #2946. --- graphics/src/text/editor.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/graphics/src/text/editor.rs b/graphics/src/text/editor.rs index 62e62f68..0051c109 100644 --- a/graphics/src/text/editor.rs +++ b/graphics/src/text/editor.rs @@ -369,6 +369,12 @@ impl editor::Editor for Editor { // Editing events Action::Edit(edit) => { + let topmost_line_before_edit = editor + .selection_bounds() + .map(|(start, _)| start) + .unwrap_or_else(|| editor.cursor()) + .line; + match edit { Edit::Insert(c) => { editor.action( @@ -417,7 +423,8 @@ impl editor::Editor for Editor { .map(|(start, _)| start) .unwrap_or(cursor); - internal.topmost_line_changed = Some(selection_start.line); + internal.topmost_line_changed = + Some(selection_start.line.min(topmost_line_before_edit)); } // Mouse events