1
0
mirror of synced 2024-11-28 09:30:51 +01:00

impr: Allow Home/End to work in hex editor view

This commit is contained in:
WerWolv 2023-12-29 11:30:23 +01:00
parent 4cbd84671c
commit 3592d17c93
3 changed files with 23 additions and 0 deletions

View File

@ -782,6 +782,8 @@
"hex.builtin.view.hex_editor.shortcut.cursor_left": "Move cursor to the left",
"hex.builtin.view.hex_editor.shortcut.selection_up": "Move selection up",
"hex.builtin.view.hex_editor.shortcut.cursor_up": "Move cursor up",
"hex.builtin.view.hex_editor.shortcut.cursor_start": "Move cursor to line start",
"hex.builtin.view.hex_editor.shortcut.cursor_end": "Move cursor to line end",
"hex.builtin.view.hex_editor.shortcut.selection_down": "Move selection down",
"hex.builtin.view.hex_editor.shortcut.cursor_down": "Move cursor down",
"hex.builtin.view.hex_editor.shortcut.selection_page_up": "Move selection up one page",

View File

@ -851,6 +851,26 @@ namespace hex::plugin::builtin {
m_hexEditor.jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, Keys::Home, "hex.builtin.view.hex_editor.shortcut.cursor_start", [this] {
auto selection = getSelection();
auto cursor = m_hexEditor.getCursorPosition().value_or(selection.getEndAddress());
auto pos = cursor - cursor % m_hexEditor.getBytesPerRow();
this->setSelection(pos, (pos + m_hexEditor.getBytesPerCell()) - 1);
m_hexEditor.scrollToSelection();
m_hexEditor.jumpIfOffScreen();
});
ShortcutManager::addShortcut(this, Keys::End, "hex.builtin.view.hex_editor.shortcut.cursor_end", [this] {
auto selection = getSelection();
auto cursor = m_hexEditor.getCursorPosition().value_or(selection.getEndAddress());
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();
});
// Move selection around
ShortcutManager::addShortcut(this, SHIFT + Keys::Up, "hex.builtin.view.hex_editor.shortcut.selection_up", [this] {
auto selection = getSelection();

View File

@ -407,6 +407,7 @@ namespace hex::ui {
m_visibleRowCount = ImGui::GetWindowSize().y / CharacterSize.y;
m_visibleRowCount = std::clamp<u32>(m_visibleRowCount, 1, numRows - m_scrollPosition);
// Loop over rows
for (ImS64 y = m_scrollPosition; y < (m_scrollPosition + m_visibleRowCount + 5) && y < numRows && numRows != 0; y++) {