LibGUI: Handle some edge cases in the spanned text drawing algorithm

This commit makes it skip invalid ranges and whine about overlapping
spans before ignoring them (instead of crashing).
This commit is contained in:
AnotherTest 2021-03-02 09:36:52 +03:30 committed by Andreas Kling
commit 0d17cf121c
Notes: sideshowbarker 2024-07-18 21:43:41 +09:00

View file

@ -531,6 +531,10 @@ void TextEditor::paint_event(PaintEvent& event)
break;
}
auto& span = document().spans()[span_index];
if (!span.range.is_valid()) {
++span_index;
continue;
}
if (span.range.end().line() < line_index) {
dbgln("spans not sorted (span end {}:{} is before current line {}) => ignoring", span.range.end().line(), span.range.end().column(), line_index);
++span_index;
@ -562,6 +566,11 @@ void TextEditor::paint_event(PaintEvent& event)
} else {
span_start = span.range.start().column() - start_of_visual_line;
}
if (span_start < next_column) {
dbgln("span started before the current position, maybe two spans overlap? (span start {} is before current position {}) => ignoring", span_start, next_column);
++span_index;
continue;
}
size_t span_end;
bool span_consumned;
if (span.range.end().line() > line_index || span.range.end().column() >= start_of_visual_line + visual_line_text.length()) {