diff --git a/VoiceInk/HotkeyManager.swift b/VoiceInk/HotkeyManager.swift index de47d48..f9f3e71 100644 --- a/VoiceInk/HotkeyManager.swift +++ b/VoiceInk/HotkeyManager.swift @@ -6,6 +6,7 @@ import AppKit extension KeyboardShortcuts.Name { static let toggleMiniRecorder = Self("toggleMiniRecorder") static let toggleMiniRecorder2 = Self("toggleMiniRecorder2") + static let pasteLastTranscription = Self("pasteLastTranscription") } @MainActor @@ -119,6 +120,16 @@ class HotkeyManager: ObservableObject { self.selectedHotkey2 = HotkeyOption(rawValue: UserDefaults.standard.string(forKey: "selectedHotkey2") ?? "") ?? .none self.whisperState = whisperState self.miniRecorderShortcutManager = MiniRecorderShortcutManager(whisperState: whisperState) + + // Register Paste Last Transcription shortcut (Control + V) + let pasteShortcut = KeyboardShortcuts.Shortcut(.v, modifiers: [.control]) + KeyboardShortcuts.setShortcut(pasteShortcut, for: .pasteLastTranscription) + KeyboardShortcuts.onKeyUp(for: .pasteLastTranscription) { [weak self] in + guard let self = self else { return } + Task { @MainActor in + LastTranscriptionService.pasteLastTranscription(from: self.whisperState.modelContext) + } + } Task { @MainActor in try? await Task.sleep(nanoseconds: 100_000_000) diff --git a/VoiceInk/Services/LastTranscriptionService.swift b/VoiceInk/Services/LastTranscriptionService.swift index 5193923..35dbff3 100644 --- a/VoiceInk/Services/LastTranscriptionService.swift +++ b/VoiceInk/Services/LastTranscriptionService.swift @@ -45,4 +45,30 @@ class LastTranscriptionService: ObservableObject { } } } + + static func pasteLastTranscription(from modelContext: ModelContext) { + guard let lastTranscription = getLastTranscription(from: modelContext) else { + Task { @MainActor in + NotificationManager.shared.showNotification( + title: "No transcription available", + type: .error + ) + } + return + } + + // Use enhanced text if available and not empty, otherwise use original text + let textToPaste: String + if let enhancedText = lastTranscription.enhancedText, !enhancedText.isEmpty { + textToPaste = enhancedText + } else { + textToPaste = lastTranscription.text + } + + // Delay to give the user time to release modifier keys (especially Control) + DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) { + CursorPaster.pasteAtCursor(textToPaste + " ", shouldPreserveClipboard: true) + } + + } } \ No newline at end of file