native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #116 from supabitapp/feat/ctrl-hold-hotkeys

Show shortcut hints when holding Control

authored by

khoi and committed by
GitHub
7991923e f1da6315

+26 -2
+6 -2
supacode/App/CommandKeyObserver.swift
··· 24 24 private func configureObservers() { 25 25 monitor = NSEvent.addLocalMonitorForEvents(matching: .flagsChanged) { [weak self] event in 26 26 MainActor.assumeIsolated { 27 - self?.handleCommandKeyChange(isDown: event.modifierFlags.contains(.command)) 27 + self?.handleCommandKeyChange(isDown: Self.shouldShowShortcuts(for: event.modifierFlags)) 28 28 } 29 29 return event 30 30 } ··· 35 35 queue: .main 36 36 ) { [weak self] _ in 37 37 MainActor.assumeIsolated { 38 - self?.handleCommandKeyChange(isDown: NSEvent.modifierFlags.contains(.command)) 38 + self?.handleCommandKeyChange(isDown: Self.shouldShowShortcuts(for: NSEvent.modifierFlags)) 39 39 } 40 40 } 41 41 didResignActiveObserver = center.addObserver( ··· 47 47 self?.handleCommandKeyChange(isDown: false) 48 48 } 49 49 } 50 + } 51 + 52 + nonisolated static func shouldShowShortcuts(for modifierFlags: NSEvent.ModifierFlags) -> Bool { 53 + modifierFlags.contains(.command) || modifierFlags.contains(.control) 50 54 } 51 55 52 56 private func handleCommandKeyChange(isDown: Bool) {
+20
supacodeTests/CommandKeyObserverTests.swift
··· 1 + import AppKit 2 + import Testing 3 + 4 + @testable import supacode 5 + 6 + struct CommandKeyObserverTests { 7 + @Test func shouldShowShortcutsForCommandOrControl() { 8 + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.command])) 9 + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.control])) 10 + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.command, .shift])) 11 + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.control, .option])) 12 + } 13 + 14 + @Test func shouldNotShowShortcutsForOtherModifiers() { 15 + #expect(CommandKeyObserver.shouldShowShortcuts(for: []) == false) 16 + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.shift]) == false) 17 + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.option]) == false) 18 + #expect(CommandKeyObserver.shouldShowShortcuts(for: [.shift, .option]) == false) 19 + } 20 + }