1
0
mirror of synced 2025-02-17 18:59:21 +01:00

fix: Duplicate shortcuts not highlighting correctly

This commit is contained in:
WerWolv 2023-11-24 20:17:01 +01:00
parent 920c6f6507
commit b050039e35
2 changed files with 11 additions and 9 deletions

View File

@ -108,13 +108,13 @@ namespace hex {
} }
static bool updateShortcutImpl(const Shortcut &oldShortcut, const Shortcut &newShortcut, std::map<Shortcut, ShortcutManager::ShortcutEntry> &shortcuts) { static bool updateShortcutImpl(const Shortcut &oldShortcut, const Shortcut &newShortcut, std::map<Shortcut, ShortcutManager::ShortcutEntry> &shortcuts) {
if (shortcuts.contains(oldShortcut + CurrentView)) { if (shortcuts.contains(oldShortcut)) {
if (shortcuts.contains(newShortcut + CurrentView)) if (shortcuts.contains(newShortcut))
return false; return false;
shortcuts[newShortcut + CurrentView] = shortcuts[oldShortcut + CurrentView]; shortcuts[newShortcut] = shortcuts[oldShortcut];
shortcuts[newShortcut + CurrentView].shortcut = newShortcut + CurrentView; shortcuts[newShortcut].shortcut = newShortcut;
shortcuts.erase(oldShortcut + CurrentView); shortcuts.erase(oldShortcut);
} }
return true; return true;
@ -126,7 +126,7 @@ namespace hex {
bool result; bool result;
if (view != nullptr) { if (view != nullptr) {
result = updateShortcutImpl(oldShortcut, newShortcut, view->m_shortcuts); result = updateShortcutImpl(oldShortcut + CurrentView, newShortcut + CurrentView , view->m_shortcuts);
} else { } else {
result = updateShortcutImpl(oldShortcut, newShortcut, s_globalShortcuts); result = updateShortcutImpl(oldShortcut, newShortcut, s_globalShortcuts);
} }

View File

@ -285,7 +285,7 @@ namespace hex::plugin::builtin {
private: private:
bool detectShortcut() { 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()); log::info("Changed shortcut to {}", shortcut->toString());
auto keys = this->m_shortcut.getKeys(); auto keys = this->m_shortcut.getKeys();
std::erase_if(keys, [](Key key) { std::erase_if(keys, [](Key key) {
@ -298,9 +298,11 @@ namespace hex::plugin::builtin {
auto newShortcut = Shortcut(std::move(keys)); auto newShortcut = Shortcut(std::move(keys));
this->m_hasDuplicate = !ShortcutManager::updateShortcut(this->m_shortcut, newShortcut, this->m_view); 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; return false;