feat: copy and paste selected emoji
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import AppKit
|
||||
import ConjureKit
|
||||
import CoreText
|
||||
import ApplicationServices
|
||||
|
||||
@MainActor
|
||||
final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSearchFieldDelegate, NSTableViewDataSource, NSTableViewDelegate {
|
||||
@@ -760,6 +761,32 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
}
|
||||
}
|
||||
|
||||
private func pasteEmoji() {
|
||||
let target = previousApplication
|
||||
let changeCount = NSPasteboard.general.changeCount
|
||||
dismiss()
|
||||
guard let target, !target.isTerminated,
|
||||
target.processIdentifier != ProcessInfo.processInfo.processIdentifier,
|
||||
AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary)
|
||||
else { return }
|
||||
Task { [weak self] in
|
||||
// Wait for focus restoration; never paste into a different app or a reopened launcher.
|
||||
for _ in 0..<20 {
|
||||
try? await Task.sleep(for: .milliseconds(25))
|
||||
guard let self, self.window?.isVisible == false, !target.isTerminated,
|
||||
NSPasteboard.general.changeCount == changeCount else { return }
|
||||
guard NSWorkspace.shared.frontmostApplication?.processIdentifier == target.processIdentifier else { continue }
|
||||
guard let down = CGEvent(keyboardEventSource: nil, virtualKey: 9, keyDown: true),
|
||||
let up = CGEvent(keyboardEventSource: nil, virtualKey: 9, keyDown: false) else { return }
|
||||
down.flags = .maskCommand
|
||||
up.flags = .maskCommand
|
||||
down.postToPid(target.processIdentifier)
|
||||
up.postToPid(target.processIdentifier)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func goBackCommand() {
|
||||
translation?.goBack()
|
||||
emojiPicker?.goBack()
|
||||
@@ -790,6 +817,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
tool.input = { [weak self] in self?.searchField.stringValue ?? "" }
|
||||
tool.focusSearch = { [weak self] in self?.window?.makeFirstResponder(self?.searchField) }
|
||||
tool.copied = { [weak self] in self?.dismiss() }
|
||||
tool.pasteRequested = { [weak self] in self?.pasteEmoji() }
|
||||
controller = tool
|
||||
placeholder = "Search emoji by name or :shortcode:…"
|
||||
accessibilityLabel = "Search emoji"
|
||||
|
||||
Reference in New Issue
Block a user