From d12f5016e43b72df169764f7cb4d90b74ecec3da Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 9 Nov 2023 16:07:14 +0100 Subject: [PATCH] fix: PageUp/PageDown being slightly weird --- .../source/content/views/view_hex_editor.cpp | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 45b5a3164..aaf57d4a0 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -830,7 +830,7 @@ namespace hex::plugin::builtin { u64 visibleByteCount = this->m_hexEditor.getBytesPerRow() * this->m_hexEditor.getVisibleRowCount(); if (cursor >= visibleByteCount) { auto pos = cursor - visibleByteCount; - this->setSelection(pos, pos + this->m_hexEditor.getBytesPerCell()); + this->setSelection(pos, (pos + this->m_hexEditor.getBytesPerCell()) - 1); this->m_hexEditor.scrollToSelection(); this->m_hexEditor.jumpIfOffScreen(); } @@ -840,7 +840,7 @@ namespace hex::plugin::builtin { auto cursor = this->m_hexEditor.getCursorPosition().value_or(selection.getEndAddress()); auto pos = cursor + (this->m_hexEditor.getBytesPerRow() * this->m_hexEditor.getVisibleRowCount()); - this->setSelection(pos, pos + this->m_hexEditor.getBytesPerCell()); + this->setSelection(pos, (pos + this->m_hexEditor.getBytesPerCell()) - 1); this->m_hexEditor.scrollToSelection(); this->m_hexEditor.jumpIfOffScreen(); }); @@ -914,22 +914,37 @@ namespace hex::plugin::builtin { this->m_hexEditor.scrollToSelection(); this->m_hexEditor.jumpIfOffScreen(); }); - ShortcutManager::addShortcut(this, Keys::PageUp, [this] { + ShortcutManager::addShortcut(this, SHIFT + Keys::PageUp, [this] { auto selection = getSelection(); - u64 visibleByteCount = this->m_hexEditor.getBytesPerRow() * this->m_hexEditor.getVisibleRowCount(); + auto cursor = this->m_hexEditor.getCursorPosition().value_or(selection.getEndAddress()); - if (selection.getEndAddress() >= visibleByteCount) { - auto pos = selection.getEndAddress() - visibleByteCount; - this->setSelection(pos, selection.getEndAddress()); - this->m_hexEditor.scrollToSelection(); - this->m_hexEditor.jumpIfOffScreen(); + if (cursor != selection.getStartAddress()) { + auto newCursor = std::max(cursor, this->m_hexEditor.getBytesPerRow()) - this->m_hexEditor.getBytesPerRow() * this->m_hexEditor.getVisibleRowCount(); + setSelection(selection.getStartAddress(), newCursor); + this->m_hexEditor.setCursorPosition(newCursor); + } else { + auto newCursor = std::max(cursor, this->m_hexEditor.getBytesPerRow()) - this->m_hexEditor.getBytesPerRow() * this->m_hexEditor.getVisibleRowCount(); + setSelection(newCursor, selection.getEndAddress()); + this->m_hexEditor.setCursorPosition(newCursor); + } + + this->m_hexEditor.scrollToSelection(); + this->m_hexEditor.jumpIfOffScreen(); + }); + ShortcutManager::addShortcut(this, SHIFT + Keys::PageDown, [this] { + auto selection = getSelection(); + auto cursor = this->m_hexEditor.getCursorPosition().value_or(selection.getEndAddress()); + + if (cursor != selection.getStartAddress()) { + auto newCursor = cursor + (this->m_hexEditor.getBytesPerRow() * this->m_hexEditor.getVisibleRowCount()); + setSelection(selection.getStartAddress(), newCursor); + this->m_hexEditor.setCursorPosition(newCursor); + } else { + auto newCursor = cursor + (this->m_hexEditor.getBytesPerRow() * this->m_hexEditor.getVisibleRowCount()); + setSelection(newCursor, selection.getEndAddress()); + this->m_hexEditor.setCursorPosition(newCursor); } - }); - ShortcutManager::addShortcut(this, Keys::PageDown, [this] { - auto selection = getSelection(); - auto pos = selection.getEndAddress() + (this->m_hexEditor.getBytesPerRow() * this->m_hexEditor.getVisibleRowCount()); - this->setSelection(pos, selection.getEndAddress()); this->m_hexEditor.scrollToSelection(); this->m_hexEditor.jumpIfOffScreen(); });