summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-05-06 22:04:53 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-05-06 22:04:53 +0200
commit26110f7753263e37f88c26ceeafda6e6b37b2a4a (patch)
tree4df3ecf6f2f34844f28fea1b14f265e7e8f692b2 /LibGUI
parent72cbcd8e98ff29fc3fd1f1d55dedd74d1e31f505 (diff)
downloadserenity-26110f7753263e37f88c26ceeafda6e6b37b2a4a.zip
GTextEditor: set_cursor() should gracefully handle old cursor being invalid.
Since set_cursor() may be called after arbitrary document changes, it can't rely on the old cursor being valid. To make things simple, if the old cursor is on a line no longer in the document, just repaint the whole editor.
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GTextEditor.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp
index 3f8776c60e..487a55ba9c 100644
--- a/LibGUI/GTextEditor.cpp
+++ b/LibGUI/GTextEditor.cpp
@@ -688,7 +688,10 @@ void GTextEditor::set_cursor(const GTextPosition& position)
ASSERT(position.line() < m_lines.size());
ASSERT(position.column() <= m_lines[position.line()]->length());
if (m_cursor != position) {
- auto old_cursor_line_rect = line_widget_rect(m_cursor.line());
+ // NOTE: If the old cursor is no longer valid, repaint everything just in case.
+ auto old_cursor_line_rect = m_cursor.line() < m_lines.size()
+ ? line_widget_rect(m_cursor.line())
+ : rect();
m_cursor = position;
m_cursor_state = true;
scroll_cursor_into_view();