style: use shared notes browsing and actions panels
This commit is contained in:
@@ -98,8 +98,10 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
else { self.moveSelection(by: offset) }
|
||||
}
|
||||
window.commandNavigation = { [weak self] key in
|
||||
self?.translation?.handleControlKey(key) ?? self?.emojiPicker?.handleControlKey(key) ?? false
|
||||
self?.notes?.handleControlKey(key) ?? self?.translation?.handleControlKey(key)
|
||||
?? self?.emojiPicker?.handleControlKey(key) ?? false
|
||||
}
|
||||
window.commandShortcut = { [weak self] key in self?.notes?.handleCommandKey(key) ?? false }
|
||||
window.usesTextNavigation = { [weak self] in self?.notes != nil }
|
||||
window.dismiss = { [weak self] in self?.dismiss() }
|
||||
window.escape = { [weak self] in self?.handleEscape() }
|
||||
@@ -476,7 +478,8 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
|
||||
private func handleEscape() {
|
||||
let selector = #selector(NSResponder.cancelOperation(_:))
|
||||
if actions.handle(selector) || translation?.handle(selector) == true || emojiPicker?.handle(selector) == true { return }
|
||||
if actions.handle(selector) || notes?.handle(selector) == true
|
||||
|| translation?.handle(selector) == true || emojiPicker?.handle(selector) == true { return }
|
||||
dismiss()
|
||||
}
|
||||
|
||||
@@ -485,6 +488,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
handleEscape()
|
||||
return true
|
||||
}
|
||||
if let notes { return notes.handle(commandSelector) }
|
||||
if let emojiPicker { return emojiPicker.handle(commandSelector) }
|
||||
if let translation { return translation.handle(commandSelector) }
|
||||
switch commandSelector {
|
||||
@@ -807,8 +811,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
|
||||
@discardableResult
|
||||
private func closeCommand() -> Bool {
|
||||
guard saveNotes() else { return false }
|
||||
notes?.closed?()
|
||||
guard notes?.close() != false else { return false }
|
||||
translation?.close()
|
||||
emojiPicker?.close()
|
||||
return true
|
||||
@@ -1200,6 +1203,7 @@ final class LauncherPanel: NSPanel {
|
||||
var numberHintsChanged: (() -> Void)?
|
||||
var launchNumber: ((Int) -> Void)?
|
||||
var commandNavigation: ((String) -> Bool)?
|
||||
var commandShortcut: ((String) -> Bool)?
|
||||
var usesTextNavigation: (() -> Bool)?
|
||||
private var numberShortcuts = CommandNumberShortcuts()
|
||||
private var commandHoldTask: Task<Void, Never>?
|
||||
@@ -1304,18 +1308,20 @@ final class LauncherPanel: NSPanel {
|
||||
}
|
||||
resetNumberHints(modifierFlags: event.modifierFlags)
|
||||
}
|
||||
if event.type == .keyDown, attachedSheet == nil, usesTextNavigation?() != true,
|
||||
if event.type == .keyDown, attachedSheet == nil,
|
||||
event.modifierFlags.intersection([.control, .command, .option, .shift]) == .control {
|
||||
if commandNavigation?(event.charactersIgnoringModifiers?.lowercased() ?? "") == true { return }
|
||||
switch event.charactersIgnoringModifiers?.lowercased() {
|
||||
case "j":
|
||||
navigateSelection?(1)
|
||||
return
|
||||
case "k":
|
||||
navigateSelection?(-1)
|
||||
return
|
||||
default:
|
||||
break
|
||||
if usesTextNavigation?() != true {
|
||||
switch event.charactersIgnoringModifiers?.lowercased() {
|
||||
case "j":
|
||||
navigateSelection?(1)
|
||||
return
|
||||
case "k":
|
||||
navigateSelection?(-1)
|
||||
return
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
super.sendEvent(event)
|
||||
@@ -1324,6 +1330,15 @@ final class LauncherPanel: NSPanel {
|
||||
}
|
||||
}
|
||||
|
||||
override func performKeyEquivalent(with event: NSEvent) -> Bool {
|
||||
if attachedSheet == nil,
|
||||
event.modifierFlags.intersection([.command, .control, .option, .shift]) == .command,
|
||||
commandShortcut?(event.charactersIgnoringModifiers?.lowercased() ?? "") == true {
|
||||
return true
|
||||
}
|
||||
return super.performKeyEquivalent(with: event)
|
||||
}
|
||||
|
||||
override func cancelOperation(_ sender: Any?) {
|
||||
if let escape { escape() } else { dismiss?() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user