From ed0553fe1049cb6c11a8032b1b8b0c0b6a57bff2 Mon Sep 17 00:00:00 2001 From: Andrew Weller Date: Sun, 25 Aug 2019 22:06:19 -0600 Subject: [PATCH] GTextEditor: Fixed bug on KeyCode::Key_Right pressed. Pressing right did nothing when the very last characters of the buffer were selected. The expected action would be for the cursor to move to the end of the buffer. This patch fixes that. --- Libraries/LibGUI/GTextEditor.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp index 7a42218e66..622503d07f 100644 --- a/Libraries/LibGUI/GTextEditor.cpp +++ b/Libraries/LibGUI/GTextEditor.cpp @@ -545,24 +545,21 @@ void GTextEditor::keydown_event(GKeyEvent& event) return; } if (event.key() == KeyCode::Key_Right) { + int new_line = m_cursor.line(); + int new_column = m_cursor.column(); if (m_cursor.column() < current_line().length()) { - int new_column = m_cursor.column() + 1; - toggle_selection_if_needed_for_event(event); - set_cursor(m_cursor.line(), new_column); - if (m_selection.start().is_valid()) { - m_selection.set_end(m_cursor); - did_update_selection(); - } + new_line = m_cursor.line(); + new_column = m_cursor.column() + 1; } else if (m_cursor.line() != line_count() - 1) { - int new_line = m_cursor.line() + 1; - int new_column = 0; - toggle_selection_if_needed_for_event(event); - set_cursor(new_line, new_column); - if (m_selection.start().is_valid()) { - m_selection.set_end(m_cursor); - did_update_selection(); - } - } + new_line = m_cursor.line() + 1; + new_column = 0; + } + toggle_selection_if_needed_for_event(event); + set_cursor(new_line, new_column); + if (m_selection.start().is_valid()) { + m_selection.set_end(m_cursor); + did_update_selection(); + } return; } if (!event.ctrl() && event.key() == KeyCode::Key_Home) {