HackStudio: Don't use an OOB TextRange when looking for hovered text

We could going +1 past the end of a TextDocumentLine here. This caused
us to crash in the brave new world, so we could find it. :^)
This commit is contained in:
Andreas Kling 2020-05-18 20:43:57 +02:00
parent 4b202a3c79
commit a1e7aa330c
Notes: sideshowbarker 2024-07-19 06:29:08 +09:00

View file

@ -234,7 +234,8 @@ void Editor::mousemove_event(GUI::MouseEvent& event)
if (span.range.contains(text_position)) {
auto adjusted_range = span.range;
adjusted_range.end().set_column(adjusted_range.end().column() + 1);
auto end_line_length = document().line(span.range.end().line()).length();
adjusted_range.end().set_column(min(end_line_length, adjusted_range.end().column() + 1));
auto hovered_span_text = document().text_in_range(adjusted_range);
#ifdef EDITOR_DEBUG
dbg() << "Hovering: " << adjusted_range << " \"" << hovered_span_text << "\"";