Skip to content

Commit

Permalink
impr: Don't scroll hex editor view when jumping to a region that's on…
Browse files Browse the repository at this point in the history
…-screen already

Fixes #1743
  • Loading branch information
WerWolv committed Jun 7, 2024
1 parent ff20f81 commit 6fd3fa7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
4 changes: 4 additions & 0 deletions plugins/builtin/include/content/views/view_hex_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ namespace hex::plugin::builtin {
m_hexEditor.jumpToSelection();
}

void jumpIfOffScreen() {
m_hexEditor.jumpIfOffScreen();
}

private:
void drawPopup();

Expand Down
16 changes: 1 addition & 15 deletions plugins/builtin/source/content/views/view_hex_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,6 @@ namespace hex::plugin::builtin {
if (cursor >= m_hexEditor.getBytesPerRow()) {
auto pos = cursor - m_hexEditor.getBytesPerRow();
this->setSelection(pos, pos);
m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
}
});
Expand All @@ -773,7 +772,6 @@ namespace hex::plugin::builtin {

auto pos = cursor + m_hexEditor.getBytesPerRow();
this->setSelection(pos, pos);
m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, Keys::Left, "hex.builtin.view.hex_editor.shortcut.cursor_left", [this] {
Expand All @@ -783,7 +781,6 @@ namespace hex::plugin::builtin {
if (cursor > 0) {
auto pos = cursor - m_hexEditor.getBytesPerCell();
this->setSelection(pos, pos);
m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
}
});
Expand All @@ -793,7 +790,6 @@ namespace hex::plugin::builtin {

auto pos = cursor + m_hexEditor.getBytesPerCell();
this->setSelection(pos, pos);
m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});

Expand All @@ -805,7 +801,6 @@ namespace hex::plugin::builtin {
if (cursor >= visibleByteCount) {
auto pos = cursor - visibleByteCount;
this->setSelection(pos, (pos + m_hexEditor.getBytesPerCell()) - 1);
m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
}
});
Expand All @@ -815,7 +810,6 @@ namespace hex::plugin::builtin {

auto pos = cursor + (m_hexEditor.getBytesPerRow() * m_hexEditor.getVisibleRowCount());
this->setSelection(pos, (pos + m_hexEditor.getBytesPerCell()) - 1);
m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});

Expand All @@ -825,7 +819,6 @@ namespace hex::plugin::builtin {

auto pos = cursor - cursor % m_hexEditor.getBytesPerRow();
this->setSelection(pos, (pos + m_hexEditor.getBytesPerCell()) - 1);
m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});

Expand All @@ -835,7 +828,6 @@ namespace hex::plugin::builtin {

auto pos = cursor - cursor % m_hexEditor.getBytesPerRow() + m_hexEditor.getBytesPerRow() - m_hexEditor.getBytesPerCell();
this->setSelection(pos, (pos + m_hexEditor.getBytesPerCell()) - 1);
m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});

Expand All @@ -854,7 +846,6 @@ namespace hex::plugin::builtin {
m_hexEditor.setCursorPosition(newCursor);
}

m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, SHIFT + Keys::Down, "hex.builtin.view.hex_editor.shortcut.selection_down", [this] {
Expand All @@ -871,7 +862,6 @@ namespace hex::plugin::builtin {
m_hexEditor.setCursorPosition(newCursor);
}

m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, SHIFT + Keys::Left, "hex.builtin.view.hex_editor.shortcut.selection_left", [this] {
Expand All @@ -888,7 +878,6 @@ namespace hex::plugin::builtin {
m_hexEditor.setCursorPosition(newCursor);
}

m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, SHIFT + Keys::Right, "hex.builtin.view.hex_editor.shortcut.selection_right", [this] {
Expand All @@ -905,7 +894,6 @@ namespace hex::plugin::builtin {
m_hexEditor.setCursorPosition(newCursor);
}

m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, SHIFT + Keys::PageUp, "hex.builtin.view.hex_editor.shortcut.selection_page_up", [this] {
Expand All @@ -922,7 +910,6 @@ namespace hex::plugin::builtin {
m_hexEditor.setCursorPosition(newCursor);
}

m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, SHIFT + Keys::PageDown, "hex.builtin.view.hex_editor.shortcut.selection_page_down", [this] {
Expand All @@ -939,7 +926,6 @@ namespace hex::plugin::builtin {
m_hexEditor.setCursorPosition(newCursor);
}

m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});

Expand All @@ -964,7 +950,7 @@ namespace hex::plugin::builtin {
if (region.size != 0) {
provider->setCurrentPage(page.value());
this->setSelection(region);
this->jumpToSelection();
this->jumpIfOffScreen();
}
});

Expand Down
1 change: 1 addition & 0 deletions plugins/ui/include/ui/hex_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ namespace hex::ui {
}

void jumpIfOffScreen() {
m_shouldScrollToSelection = true;
m_shouldJumpWhenOffScreen = true;
}

Expand Down

0 comments on commit 6fd3fa7

Please sign in to comment.