1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:28:11 +00:00

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.
This commit is contained in:
Sam Atkins 2023-02-21 12:41:15 +00:00 committed by Andreas Kling
parent db886fe18b
commit e8b7bdbd57

View file

@ -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()) {