diff options
author | Andreas Kling <kling@serenityos.org> | 2020-01-27 22:58:50 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-01-27 22:59:46 +0100 |
commit | c5db596c78b1e8c81ab38b96a1888cce82998210 (patch) | |
tree | 5d584dee537c9f72fb6761c92b1e6ebcdfa1cbe6 /Libraries | |
parent | 169a38113eec9a95426603d8221e8bdc96a23aaa (diff) | |
download | serenity-c5db596c78b1e8c81ab38b96a1888cce82998210.zip |
LibGUI: Fix crash when trying to scroll above the head of the document
We can't go higher than line 0. Can't rely on max() here since line
numbers are unsigned.
Fixes #1145.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/GTextEditor.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp index ef041c5ca9..baccab38c7 100644 --- a/Libraries/LibGUI/GTextEditor.cpp +++ b/Libraries/LibGUI/GTextEditor.cpp @@ -650,7 +650,8 @@ void GTextEditor::keydown_event(GKeyEvent& event) } if (event.key() == KeyCode::Key_PageUp) { if (m_cursor.line() > 0) { - size_t new_line = max((size_t)0, m_cursor.line() - (size_t)visible_content_rect().height() / (size_t)line_height()); + size_t page_step = (size_t)visible_content_rect().height() / (size_t)line_height(); + size_t new_line = m_cursor.line() < page_step ? 0 : m_cursor.line() - page_step; size_t new_column = min(m_cursor.column(), line(new_line).length()); toggle_selection_if_needed_for_event(event); set_cursor(new_line, new_column); |