Skip to content

Commit c161982

Browse files
committed
impr: Jump to top of selection instead of the bottom
Fixes #2354
1 parent 88ccb0e commit c161982

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

plugins/ui/include/ui/hex_editor.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ namespace hex::ui {
5555
}
5656

5757
ScrollPosition& operator=(ImS64 value) {
58+
if (value < 0)
59+
value = 0;
60+
5861
this->get() = value;
5962
return *this;
6063
}
@@ -157,7 +160,7 @@ namespace hex::ui {
157160

158161
m_selectionStart = std::clamp<u64>(start, 0, maxAddress);
159162
m_selectionEnd = std::clamp<u64>(end, 0, maxAddress);
160-
m_cursorPosition = m_selectionEnd;
163+
m_cursorPosition = m_selectionStart;
161164

162165
if (m_selectionChanged) {
163166
auto selection = this->getSelection();

plugins/ui/source/ui/hex_editor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,15 +1054,15 @@ namespace hex::ui {
10541054

10551055
// Calculate the current top and bottom row numbers of the viewport
10561056
ImS64 currentTopRow = m_scrollPosition;
1057-
ImS64 currentBottomRow = m_scrollPosition + m_visibleRowCount - 3;
1057+
ImS64 currentBottomRow = std::max<ImS64>(m_scrollPosition + m_visibleRowCount - 3, 0);
10581058

10591059
// Check if the targetRowNumber is outside the current visible range
10601060
if (ImS64(targetRowNumber) < currentTopRow) {
10611061
// If target is above the current view, scroll just enough to bring it into view at the top
1062-
m_scrollPosition = targetRowNumber - (m_visibleRowCount * m_jumpPivot);
1062+
m_scrollPosition = targetRowNumber + m_visibleRowCount * m_jumpPivot - 3;
10631063
} else if (ImS64(targetRowNumber) > currentBottomRow) {
10641064
// If target is below the current view, scroll just enough to bring it into view at the bottom
1065-
m_scrollPosition = targetRowNumber - (m_visibleRowCount - 3);
1065+
m_scrollPosition = targetRowNumber - 3;
10661066
}
10671067

10681068
m_jumpPivot = 0.0F;

0 commit comments

Comments
 (0)