diff --git a/src/EditableNSTextField.swift b/src/EditableNSTextField.swift index 4090b64..8499e40 100644 --- a/src/EditableNSTextField.swift +++ b/src/EditableNSTextField.swift @@ -34,6 +34,8 @@ final class EditableNSTextField: NSTextField { if NSApp.sendAction(#selector(NSResponder.selectAll(_:)), to: nil, from: self) { return true } + } else if isNumericalCode(key) { // Ignore Command + {1-9}. + return true } } else if modsContains(keys: OSCmd | OSShift, in: modifiers) { if key == kVK_ANSI_Z { diff --git a/src/Helpers.swift b/src/Helpers.swift index dc10f55..a73c065 100644 --- a/src/Helpers.swift +++ b/src/Helpers.swift @@ -11,6 +11,10 @@ func modsContains(keys: UInt, in modifiers: UInt) -> Bool { return (modifiers & keys) == keys && ((modifiers ^ keys) & OSMods) == 0 } +func isNumericalCode(_ key: UInt16) -> Bool { + return (key == kVK_ANSI_1 || key == kVK_ANSI_2 || key == kVK_ANSI_3 || key == kVK_ANSI_4 || key == kVK_ANSI_5 || key == kVK_ANSI_6 || key == kVK_ANSI_7 || key == kVK_ANSI_8 || key == kVK_ANSI_9) +} + func modsContainsNone(in modifiers: UInt) -> Bool { return (modifiers & OSMods) == 0 } diff --git a/src/SearchViewController.swift b/src/SearchViewController.swift index 7c942bb..538d51c 100644 --- a/src/SearchViewController.swift +++ b/src/SearchViewController.swift @@ -192,6 +192,16 @@ class SearchViewController: NSViewController, NSTextFieldDelegate, NSPopoverDele modsContainsNone(in: modifiers) && key == kVK_DownArrow { controller.programsTableViewSelection += 1 + } else if modsContains(keys: OSCmd, in: modifiers) && isNumericalCode(key) { + if key == kVK_ANSI_1 { controller.programsTableViewSelection = 0 } + if key == kVK_ANSI_2 { controller.programsTableViewSelection = 1 } + if key == kVK_ANSI_3 { controller.programsTableViewSelection = 2 } + if key == kVK_ANSI_4 { controller.programsTableViewSelection = 3 } + if key == kVK_ANSI_5 { controller.programsTableViewSelection = 4 } + if key == kVK_ANSI_6 { controller.programsTableViewSelection = 5 } + if key == kVK_ANSI_7 { controller.programsTableViewSelection = 6 } + if key == kVK_ANSI_8 { controller.programsTableViewSelection = 7 } + if key == kVK_ANSI_9 { controller.programsTableViewSelection = 8 } } if controller.programsTableViewSelection > controller.listIndex-1 {