From c1619820c79d89d66f3157d8c848cdd69b96206e Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 10 Sep 2025 20:50:27 +0200 Subject: [PATCH] impr: Jump to top of selection instead of the bottom Fixes #2354 --- plugins/ui/include/ui/hex_editor.hpp | 5 ++++- plugins/ui/source/ui/hex_editor.cpp | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/ui/include/ui/hex_editor.hpp b/plugins/ui/include/ui/hex_editor.hpp index 85db3194b..875d3ae37 100644 --- a/plugins/ui/include/ui/hex_editor.hpp +++ b/plugins/ui/include/ui/hex_editor.hpp @@ -55,6 +55,9 @@ namespace hex::ui { } ScrollPosition& operator=(ImS64 value) { + if (value < 0) + value = 0; + this->get() = value; return *this; } @@ -157,7 +160,7 @@ namespace hex::ui { m_selectionStart = std::clamp(start, 0, maxAddress); m_selectionEnd = std::clamp(end, 0, maxAddress); - m_cursorPosition = m_selectionEnd; + m_cursorPosition = m_selectionStart; if (m_selectionChanged) { auto selection = this->getSelection(); diff --git a/plugins/ui/source/ui/hex_editor.cpp b/plugins/ui/source/ui/hex_editor.cpp index f2342c9b2..df5c53119 100644 --- a/plugins/ui/source/ui/hex_editor.cpp +++ b/plugins/ui/source/ui/hex_editor.cpp @@ -1054,15 +1054,15 @@ namespace hex::ui { // Calculate the current top and bottom row numbers of the viewport ImS64 currentTopRow = m_scrollPosition; - ImS64 currentBottomRow = m_scrollPosition + m_visibleRowCount - 3; + ImS64 currentBottomRow = std::max(m_scrollPosition + m_visibleRowCount - 3, 0); // Check if the targetRowNumber is outside the current visible range if (ImS64(targetRowNumber) < currentTopRow) { // If target is above the current view, scroll just enough to bring it into view at the top - m_scrollPosition = targetRowNumber - (m_visibleRowCount * m_jumpPivot); + m_scrollPosition = targetRowNumber + m_visibleRowCount * m_jumpPivot - 3; } else if (ImS64(targetRowNumber) > currentBottomRow) { // If target is below the current view, scroll just enough to bring it into view at the bottom - m_scrollPosition = targetRowNumber - (m_visibleRowCount - 3); + m_scrollPosition = targetRowNumber - 3; } m_jumpPivot = 0.0F;