fix: Moving Hex Editor cursor downwards jumping entire page at once

This commit is contained in:
WerWolv
2024-01-29 23:29:18 +01:00
parent 18b717594f
commit ba6373daa4
2 changed files with 10 additions and 17 deletions

View File

@@ -181,11 +181,9 @@ namespace hex::ui {
return m_selectionStart.has_value() && m_selectionEnd.has_value();
}
void jumpToSelection(bool center = true) {
void jumpToSelection(float pivot = 0.0F) {
m_shouldJumpToSelection = true;
if (center)
m_centerOnJump = true;
m_jumpPivot = pivot;
}
void scrollToSelection() {
@@ -310,7 +308,7 @@ namespace hex::ui {
char m_unknownDataCharacter = '?';
bool m_shouldJumpToSelection = false;
bool m_centerOnJump = false;
float m_jumpPivot = 0.0F;
bool m_shouldScrollToSelection = false;
bool m_shouldJumpWhenOffScreen = false;
bool m_shouldUpdateScrollPosition = false;

View File

@@ -489,8 +489,8 @@ namespace hex::ui {
}
m_visibleRowCount = ImGui::GetWindowSize().y / CharacterSize.y;
m_visibleRowCount = std::clamp<i64>(m_visibleRowCount, 1, numRows - m_scrollPosition);
m_visibleRowCount = size.y / CharacterSize.y;
m_visibleRowCount = std::max<i64>(m_visibleRowCount, 1);
// Loop over rows
for (ImS64 y = m_scrollPosition; y < (m_scrollPosition + m_visibleRowCount + 5) && y < numRows && numRows != 0; y++) {
@@ -768,9 +768,9 @@ namespace hex::ui {
newSelection.address -= pageAddress;
if ((newSelection.getStartAddress()) < u64(m_scrollPosition * m_bytesPerRow))
this->jumpToSelection(false);
this->jumpToSelection(0.0F);
if ((newSelection.getEndAddress()) > u64((m_scrollPosition + m_visibleRowCount) * m_bytesPerRow))
this->jumpToSelection(false);
this->jumpToSelection(1.0F);
}
}
}
@@ -784,15 +784,10 @@ namespace hex::ui {
const auto pageAddress = m_provider->getCurrentPageAddress() + m_provider->getBaseAddress();
if (m_centerOnJump) {
m_scrollPosition = (newSelection.getStartAddress() - pageAddress) / m_bytesPerRow;
m_scrollPosition -= (m_visibleRowCount / 2);
} else {
m_scrollPosition = (newSelection.getStartAddress() - pageAddress) / m_bytesPerRow;
}
m_centerOnJump = false;
m_scrollPosition = (newSelection.getStartAddress() - pageAddress) / m_bytesPerRow;
m_scrollPosition -= m_visibleRowCount * m_jumpPivot;
m_jumpPivot = 0.0F;
}
}