diff --git a/supacode/App/CommandKeyObserver.swift b/supacode/App/CommandKeyObserver.swift index d91518e2..c7d9a321 100644 --- a/supacode/App/CommandKeyObserver.swift +++ b/supacode/App/CommandKeyObserver.swift @@ -50,7 +50,8 @@ final class CommandKeyObserver { } nonisolated static func shouldShowShortcuts(for modifierFlags: NSEvent.ModifierFlags) -> Bool { - modifierFlags.contains(.command) || modifierFlags.contains(.control) + let modifiers = modifierFlags.intersection(.deviceIndependentFlagsMask) + return modifiers == .command || modifiers == .control } private func handleCommandKeyChange(isDown: Bool) { diff --git a/supacodeTests/CommandKeyObserverTests.swift b/supacodeTests/CommandKeyObserverTests.swift index 789cd18c..30d8c1af 100644 --- a/supacodeTests/CommandKeyObserverTests.swift +++ b/supacodeTests/CommandKeyObserverTests.swift @@ -4,14 +4,19 @@ import Testing @testable import supacode struct CommandKeyObserverTests { - @Test func shouldShowShortcutsForCommandOrControl() { + @Test func shouldShowShortcutsForBareCommandOrControl() { #expect(CommandKeyObserver.shouldShowShortcuts(for: [.command])) #expect(CommandKeyObserver.shouldShowShortcuts(for: [.control])) - #expect(CommandKeyObserver.shouldShowShortcuts(for: [.command, .shift])) - #expect(CommandKeyObserver.shouldShowShortcuts(for: [.control, .option])) } - @Test func shouldNotShowShortcutsForOtherModifiers() { + @Test func shouldNotShowShortcutsForShortcutCombinations() { + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.command, .shift]) == false) + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.control, .option]) == false) + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.command, .control]) == false) + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.command, .control, .shift]) == false) + } + + @Test func shouldNotShowShortcutsForNonHintModifiers() { #expect(CommandKeyObserver.shouldShowShortcuts(for: []) == false) #expect(CommandKeyObserver.shouldShowShortcuts(for: [.shift]) == false) #expect(CommandKeyObserver.shouldShowShortcuts(for: [.option]) == false)