From bd1d384cf60a59ac507d14e5b83bf63fc0330cc1 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Fri, 15 Dec 2023 23:08:10 +0100 Subject: [PATCH] HexEditor: Remove moving cursor outside bounds if selecting with mouse Currently if users select last bytes in HexEditor with mouse in either Hex or Text mode, they will be able to move cursor on the byte outside bounds. If then they try to write something in either of those modes, app will crash. This patch moves the recently added "replace" cursor to always be on the last byte of the selection instead of being on the byte after the last selected byte. --- Userland/Applications/HexEditor/HexEditor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index 9aedb07366..6d01e93295 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -354,7 +354,7 @@ void HexEditor::mousemove_event(GUI::MouseEvent& event) return; m_selection_end = offset; - m_position = offset; + m_position = (m_selection_end <= m_selection_start) ? offset : offset - 1; scroll_position_into_view(offset); } @@ -369,7 +369,7 @@ void HexEditor::mousemove_event(GUI::MouseEvent& event) return; m_selection_end = offset; - m_position = offset; + m_position = (m_selection_end <= m_selection_start) ? offset : offset - 1; scroll_position_into_view(offset); } update_status();