summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2021-03-02 09:36:52 +0330
committerAndreas Kling <kling@serenityos.org>2021-03-04 11:21:43 +0100
commit0d17cf121ccd8522a21c54623e9a8994ed6c1ab2 (patch)
tree55083a35b0f942a7fba60aef102f57e86bb3e97a /Userland/Libraries
parent2089b24ab56b6dc336c679a311ffdec510ab59d8 (diff)
downloadserenity-0d17cf121ccd8522a21c54623e9a8994ed6c1ab2.zip
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).
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 8b8105615c..83501dc79e 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -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()) {