Browse Source

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).
AnotherTest 4 years ago
parent
commit
0d17cf121c
1 changed files with 9 additions and 0 deletions
  1. 9 0
      Userland/Libraries/LibGUI/TextEditor.cpp

+ 9 - 0
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()) {