diff --git a/lib/libimhex/include/hex/api/shortcut_manager.hpp b/lib/libimhex/include/hex/api/shortcut_manager.hpp index 940170646..da80d2c45 100644 --- a/lib/libimhex/include/hex/api/shortcut_manager.hpp +++ b/lib/libimhex/include/hex/api/shortcut_manager.hpp @@ -181,6 +181,8 @@ namespace hex { bool isLocal() const; std::string toString() const; const std::set& getKeys() const; + bool has(Key key) const; + bool matches(const Shortcut &other) const; private: friend Shortcut operator+(const Key &lhs, const Key &rhs); @@ -258,7 +260,7 @@ namespace hex { [[nodiscard]] static std::vector getGlobalShortcuts(); [[nodiscard]] static std::vector getViewShortcuts(const View *view); - [[nodiscard]] static bool updateShortcut(Shortcut oldShortcut, Shortcut newShortcut, View *view = nullptr); + [[nodiscard]] static bool updateShortcut(const Shortcut &oldShortcut, Shortcut newShortcut, View *view = nullptr); }; } \ No newline at end of file diff --git a/lib/libimhex/source/api/shortcut_manager.cpp b/lib/libimhex/source/api/shortcut_manager.cpp index 6aa644fa1..c2c838301 100644 --- a/lib/libimhex/source/api/shortcut_manager.cpp +++ b/lib/libimhex/source/api/shortcut_manager.cpp @@ -54,7 +54,26 @@ namespace hex { return m_keys.contains(CurrentView); } - const std::set& Shortcut::getKeys() const { return m_keys; } + const std::set& Shortcut::getKeys() const { + return m_keys; + } + + bool Shortcut::has(Key key) const { + return m_keys.contains(key); + } + + bool Shortcut::matches(const Shortcut& other) const { + auto left = this->m_keys; + auto right = other.m_keys; + + left.erase(CurrentView); + left.erase(AllowWhileTyping); + right.erase(CurrentView); + right.erase(AllowWhileTyping); + + return left == right; + } + std::string Shortcut::toString() const { std::string result; @@ -342,10 +361,13 @@ namespace hex { return true; } - bool ShortcutManager::updateShortcut(const Shortcut &oldShortcut, const Shortcut &newShortcut, View *view) { - if (oldShortcut == newShortcut) + bool ShortcutManager::updateShortcut(const Shortcut &oldShortcut, Shortcut newShortcut, View *view) { + if (oldShortcut.matches(newShortcut)) return true; + if (oldShortcut.has(AllowWhileTyping)) + newShortcut += AllowWhileTyping; + bool result; if (view != nullptr) { result = updateShortcutImpl(oldShortcut + CurrentView, newShortcut + CurrentView , view->m_shortcuts); diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 436b2f0f1..526f6ad3e 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -283,7 +283,7 @@ namespace hex::plugin::builtin { bool settingChanged = false; - ImGui::BeginDisabled(m_drawShortcut.match(m_defaultShortcut)); + ImGui::BeginDisabled(m_drawShortcut.matches(m_defaultShortcut)); if (ImGuiExt::IconButton(ICON_VS_X, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { m_hasDuplicate = !ShortcutManager::updateShortcut(m_shortcut, m_defaultShortcut, m_view);