Skip to content

Commit

Permalink
fix: Moving Hex Editor cursor downwards jumping entire page at once
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jan 29, 2024
1 parent 18b7175 commit ba6373d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
8 changes: 3 additions & 5 deletions plugins/ui/include/ui/hex_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 7 additions & 12 deletions plugins/ui/source/ui/hex_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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;
}

}
Expand Down

0 comments on commit ba6373d

Please sign in to comment.