diff --git a/lib/libimhex/source/api/shortcut_manager.cpp b/lib/libimhex/source/api/shortcut_manager.cpp index feb148243..10829dc7d 100644 --- a/lib/libimhex/source/api/shortcut_manager.cpp +++ b/lib/libimhex/source/api/shortcut_manager.cpp @@ -108,13 +108,13 @@ namespace hex { } static bool updateShortcutImpl(const Shortcut &oldShortcut, const Shortcut &newShortcut, std::map &shortcuts) { - if (shortcuts.contains(oldShortcut + CurrentView)) { - if (shortcuts.contains(newShortcut + CurrentView)) + if (shortcuts.contains(oldShortcut)) { + if (shortcuts.contains(newShortcut)) return false; - shortcuts[newShortcut + CurrentView] = shortcuts[oldShortcut + CurrentView]; - shortcuts[newShortcut + CurrentView].shortcut = newShortcut + CurrentView; - shortcuts.erase(oldShortcut + CurrentView); + shortcuts[newShortcut] = shortcuts[oldShortcut]; + shortcuts[newShortcut].shortcut = newShortcut; + shortcuts.erase(oldShortcut); } return true; @@ -126,7 +126,7 @@ namespace hex { bool result; if (view != nullptr) { - result = updateShortcutImpl(oldShortcut, newShortcut, view->m_shortcuts); + result = updateShortcutImpl(oldShortcut + CurrentView, newShortcut + CurrentView , view->m_shortcuts); } else { result = updateShortcutImpl(oldShortcut, newShortcut, s_globalShortcuts); } diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index a25ce32b9..9eb642953 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -285,7 +285,7 @@ namespace hex::plugin::builtin { private: bool detectShortcut() { - if (auto shortcut = ShortcutManager::getPreviousShortcut(); shortcut.has_value()) { + if (const auto &shortcut = ShortcutManager::getPreviousShortcut(); shortcut.has_value()) { log::info("Changed shortcut to {}", shortcut->toString()); auto keys = this->m_shortcut.getKeys(); std::erase_if(keys, [](Key key) { @@ -298,9 +298,11 @@ namespace hex::plugin::builtin { auto newShortcut = Shortcut(std::move(keys)); this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view); - this->m_shortcut = std::move(newShortcut); - return true; + if (!this->m_hasDuplicate) { + this->m_shortcut = std::move(newShortcut); + return true; + } } return false;