Skip to content

Commit

Permalink
Fixed an issue when a shortcut that was overridden is incorrectly rep…
Browse files Browse the repository at this point in the history
…orted as still being used (#494)
  • Loading branch information
mikekazakov authored Dec 31, 2024
1 parent 88a4db8 commit 0ad512b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")}));
Expand Down

0 comments on commit 0ad512b

Please sign in to comment.