From e8b7bdbd57e9486459c7ad10ee608c0d4942a082 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 21 Feb 2023 12:41:15 +0000 Subject: LibGUI: Skip painting TextEditor spans that end on previous lines This only becomes a problem with folding, since arbitrary lines may be invisible, meaning we try to apply a span for an invisible line N, on line N+X instead, causing occasional crashes. This check means we can remove the loop that skips spans occurring at the end of the line. --- Userland/Libraries/LibGUI/TextEditor.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index e3619f01c6..b583d46565 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -585,6 +585,10 @@ void TextEditor::paint_event(PaintEvent& event) }; while (span_index < document().spans().size()) { auto& span = document().spans()[span_index]; + if (span.range.end().line() < line_index) { + ++span_index; + continue; + } if (span.range.start().line() > line_index || (span.range.start().line() == line_index && span.range.start().column() >= start_of_visual_line + visual_line_text.length())) { // no more spans in this line, moving on @@ -624,16 +628,6 @@ void TextEditor::paint_event(PaintEvent& event) if (next_column < visual_line_text.length()) { draw_text_helper(next_column, visual_line_text.length(), unspanned_font, { unspanned_color }); } - // consume all spans that should end this line - // this is necessary since the spans can include the new line character - while (is_last_visual_line && span_index < document().spans().size()) { - auto& span = document().spans()[span_index]; - if (span.range.end().line() == line_index) { - ++span_index; - } else { - break; - } - } } if (m_visualize_trailing_whitespace && line.ends_in_whitespace()) { -- cgit v1.2.3