1
0
mirror of synced 2024-09-24 03:28:24 +02: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) {
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);
}

View File

@ -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;