Add Control+V shortcut for paste last transcription

This commit is contained in:
Beingpax 2025-08-07 13:25:38 +05:45
parent d363808a7b
commit 3fc90b43be
2 changed files with 37 additions and 0 deletions

View File

@ -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)

View File

@ -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)
}
}
}