From db2e1bfa027774ff1e1f883c4ddadc277c1e6e1e Mon Sep 17 00:00:00 2001 From: skelegorg Date: Tue, 18 Oct 2022 23:25:56 -0400 Subject: [PATCH] LibGUI: Fix EditingEngine Shift + Up/Down highlight behavior Fix unwanted behavior in the EditingEngine where using Shift + Up or Down keys will not highlight to the beginning or end of the first or last lines of the file. Fix issue #15695 --- Userland/Libraries/LibGUI/EditingEngine.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Userland/Libraries/LibGUI/EditingEngine.cpp b/Userland/Libraries/LibGUI/EditingEngine.cpp index f46535b65c..dc9f4727b1 100644 --- a/Userland/Libraries/LibGUI/EditingEngine.cpp +++ b/Userland/Libraries/LibGUI/EditingEngine.cpp @@ -87,9 +87,24 @@ bool EditingEngine::on_key(KeyEvent const& event) bool const condition_for_up = direction == VerticalDirection::Up && m_editor->cursor().line() > 0; bool const condition_for_down = direction == VerticalDirection::Down && m_editor->cursor().line() < (m_editor->line_count() - 1); + bool const condition_for_up_to_beginning = direction == VerticalDirection::Up && m_editor->cursor().line() == 0; + bool const condition_for_down_to_end = direction == VerticalDirection::Down && m_editor->cursor().line() == (m_editor->line_count() - 1); + if (condition_for_up || condition_for_down || m_editor->is_wrapping_enabled()) m_editor->update_selection(event.shift()); + // Shift + Up on the top line (or only line) selects from the cursor to the start of the line. + if (condition_for_up_to_beginning) { + m_editor->update_selection(event.shift()); + move_to_line_beginning(); + } + + // Shift + Down on the bottom line (or only line) selects from the cursor to the end of the line. + if (condition_for_down_to_end) { + m_editor->update_selection(event.shift()); + move_to_line_end(); + } + move_one_helper(event, direction); }