diff --git a/Sources/Pesty/AppController.swift b/Sources/Pesty/AppController.swift index 168016f..a7f8f12 100644 --- a/Sources/Pesty/AppController.swift +++ b/Sources/Pesty/AppController.swift @@ -442,6 +442,28 @@ final class AppController: NSObject, NSApplicationDelegate { win.makeKeyAndOrderFront(nil) } + /// Handles the small set of commands that are only meaningful while the + /// Paste Bar is active. Keeping this separate lets both the local event + /// monitor and NSPanel key-equivalent path consume the same shortcuts. + func handleBarCommandShortcut(_ event: NSEvent) -> Bool { + let flags = event.modifierFlags + guard flags.contains(.command), + flags.contains(.shift), + !flags.contains(.option), + !flags.contains(.control) else { return false } + + switch Int(event.keyCode) { + case kVK_ANSI_S: + showSettings() + return true + case kVK_ANSI_P: + togglePestyPause() + return true + default: + return false + } + } + private func startKeyMonitor() { stopKeyMonitor() keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [weak self] event in @@ -455,6 +477,8 @@ final class AppController: NSObject, NSApplicationDelegate { } private func handleKey(_ event: NSEvent) -> NSEvent? { + if handleBarCommandShortcut(event) { return nil } + let code = Int(event.keyCode) let flags = event.modifierFlags let cmd = flags.contains(.command) diff --git a/Sources/Pesty/UI/BarWindowController.swift b/Sources/Pesty/UI/BarWindowController.swift index 7161004..77d9ed1 100644 --- a/Sources/Pesty/UI/BarWindowController.swift +++ b/Sources/Pesty/UI/BarWindowController.swift @@ -8,8 +8,12 @@ final class BarPanel: NSPanel { override func performKeyEquivalent(with event: NSEvent) -> Bool { // AppKit routes Command-key combinations through key equivalents before - // SwiftUI receives a keyDown event. Handle Copy at the panel level as a - // reliable counterpart to the navigation monitor in AppController. + // SwiftUI receives a keyDown event. Handle the bar-local commands at + // the panel level as a reliable counterpart to the navigation monitor + // in AppController. + if AppController.shared.handleBarCommandShortcut(event) { + return true + } if event.keyCode == kVK_ANSI_C, event.modifierFlags.contains(.command) { AppController.shared.commandCopy() return true