diff --git a/Source/NimbleCommander/NimbleCommander/Core/ActionsShortcutsManager.mm b/Source/NimbleCommander/NimbleCommander/Core/ActionsShortcutsManager.mm index 3ca14d82d..fd0febe16 100644 --- a/Source/NimbleCommander/NimbleCommander/Core/ActionsShortcutsManager.mm +++ b/Source/NimbleCommander/NimbleCommander/Core/ActionsShortcutsManager.mm @@ -612,7 +612,9 @@ static constexpr auto make_array_n(T &&value) const Shortcuts new_shortcuts = SanitizedShortcuts(Shortcuts(_shortcuts.begin(), _shortcuts.end())); + // Search if currently this action has custom shortcuts(s) const auto override_it = m_ShortcutsOverrides.find(*tag); + if( std::ranges::equal(default_it->second, new_shortcuts) ) { // The shortcut is same as the default one for this action @@ -639,7 +641,12 @@ static constexpr auto make_array_n(T &&value) return false; // Nothing new, it's the same as currently defined in the overrides } - if( override_it != m_ShortcutsOverrides.end() ) { + if( override_it == m_ShortcutsOverrides.end() ) { + // Unregister the usage of the default override shortcuts + for( const Shortcut &shortcut : default_it->second ) + UnregisterShortcutUsage(shortcut, *tag); + } + else { // Unregister the usage of the override shortcuts for( const Shortcut &shortcut : override_it->second ) UnregisterShortcutUsage(shortcut, *tag); diff --git a/Source/NimbleCommander/NimbleCommander/Tests/ActionsShortcutsManager_UT.cpp b/Source/NimbleCommander/NimbleCommander/Tests/ActionsShortcutsManager_UT.cpp index 2da3ca37f..745f3391f 100644 --- a/Source/NimbleCommander/NimbleCommander/Tests/ActionsShortcutsManager_UT.cpp +++ b/Source/NimbleCommander/NimbleCommander/Tests/ActionsShortcutsManager_UT.cpp @@ -159,6 +159,11 @@ TEST_CASE(PREFIX "ActionTagsFromShortCut") manager.TagFromAction("menu.window.zoom").value(), }); } + SECTION("After setting an override the original is not reported as being used") + { + REQUIRE(manager.SetShortcutsOverride("menu.edit.copy", std::array{AS("⌘j")})); + REQUIRE(manager.ActionTagsFromShortcut(AS("⌘c"), "menu.") == std::nullopt); + } SECTION("After setting and removing the override its not reported as being used") { REQUIRE(manager.SetShortcutsOverride("menu.window.zoom", std::array{AS("⇧^⌘⌥k"), AS("⇧^⌘⌥j")}));