From efed07ac8bf2634837e19ea405b779e660183ea4 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 28 May 2022 22:31:40 +0200 Subject: [PATCH] ux: Fixed another hex editor scroll issue --- .../include/content/views/view_hex_editor.hpp | 5 +++++ .../source/content/views/view_hex_editor.cpp | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/builtin/include/content/views/view_hex_editor.hpp b/plugins/builtin/include/content/views/view_hex_editor.hpp index c225b1d9e..e14d935c0 100644 --- a/plugins/builtin/include/content/views/view_hex_editor.hpp +++ b/plugins/builtin/include/content/views/view_hex_editor.hpp @@ -66,6 +66,10 @@ namespace hex::plugin::builtin { this->m_shouldScrollToSelection = true; } + void jumpIfOffScreen() { + this->m_shouldJumpWhenOffScreen = true; + } + public: class Popup { public: @@ -105,6 +109,7 @@ namespace hex::plugin::builtin { bool m_shouldJumpToSelection = false; bool m_shouldScrollToSelection = false; + bool m_shouldJumpWhenOffScreen = false; bool m_selectionChanged = false; u64 m_selectionStart = InvalidSelection; diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index eafd77d74..b2ab91c83 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -845,7 +845,9 @@ namespace hex::plugin::builtin { } // If the cursor is off-screen, directly jump to the byte - if (!ImGui::IsMouseDown(ImGuiMouseButton_Left)) { + if (this->m_shouldJumpWhenOffScreen) { + this->m_shouldJumpWhenOffScreen = false; + const auto newSelection = this->getSelection(); if (newSelection.getStartAddress() < u64(clipper.DisplayStart * this->m_bytesPerRow)) this->jumpToSelection(); @@ -1059,24 +1061,28 @@ namespace hex::plugin::builtin { auto pos = this->m_selectionEnd - this->m_bytesPerRow; this->setSelection(pos, pos); this->scrollToSelection(); + this->jumpIfOffScreen(); } }); ShortcutManager::addShortcut(this, Keys::Down, [this] { auto pos = this->m_selectionEnd + this->m_bytesPerRow; this->setSelection(pos, pos); this->scrollToSelection(); + this->jumpIfOffScreen(); }); ShortcutManager::addShortcut(this, Keys::Left, [this] { if (this->m_selectionEnd > 0) { auto pos = this->m_selectionEnd - 1; this->setSelection(pos, pos); this->scrollToSelection(); + this->jumpIfOffScreen(); } }); ShortcutManager::addShortcut(this, Keys::Right, [this] { auto pos = this->m_selectionEnd + 1; this->setSelection(pos, pos); this->scrollToSelection(); + this->jumpIfOffScreen(); }); ShortcutManager::addShortcut(this, Keys::PageUp, [this] { @@ -1085,32 +1091,37 @@ namespace hex::plugin::builtin { auto pos = this->m_selectionEnd - visibleByteCount; this->setSelection(pos, pos); this->scrollToSelection(); + this->jumpIfOffScreen(); } }); ShortcutManager::addShortcut(this, Keys::PageDown, [this] { auto pos = this->m_selectionEnd + (this->m_bytesPerRow * this->m_visibleRowCount); this->setSelection(pos, pos); this->scrollToSelection(); + this->jumpIfOffScreen(); }); // Move selection around ShortcutManager::addShortcut(this, SHIFT + Keys::Up, [this] { this->setSelection(this->m_selectionEnd - this->m_bytesPerRow, this->m_selectionEnd); this->scrollToSelection(); + this->jumpIfOffScreen(); }); ShortcutManager::addShortcut(this, SHIFT + Keys::Down, [this] { this->setSelection(this->m_selectionEnd + this->m_bytesPerRow, this->m_selectionEnd); this->scrollToSelection(); + this->jumpIfOffScreen(); }); ShortcutManager::addShortcut(this, SHIFT + Keys::Left, [this] { this->setSelection(this->m_selectionEnd - 1, this->m_selectionEnd); this->scrollToSelection(); - + this->jumpIfOffScreen(); }); ShortcutManager::addShortcut(this, SHIFT + Keys::Right, [this] { this->setSelection(this->m_selectionEnd + 1, this->m_selectionEnd); this->scrollToSelection(); + this->jumpIfOffScreen(); }); ShortcutManager::addShortcut(this, CTRL + Keys::G, [this] {