diff --git a/VoiceInk/CursorPaster.swift b/VoiceInk/CursorPaster.swift index eb2c651..3525aee 100644 --- a/VoiceInk/CursorPaster.swift +++ b/VoiceInk/CursorPaster.swift @@ -4,7 +4,7 @@ import AppKit class CursorPaster { private static let pasteCompletionDelay: TimeInterval = 0.3 - static func pasteAtCursor(_ text: String) { + static func pasteAtCursor(_ text: String, shouldPreserveClipboard: Bool = true) { guard AXIsProcessTrusted() else { return } @@ -12,12 +12,15 @@ class CursorPaster { let pasteboard = NSPasteboard.general var savedContents: [(NSPasteboard.PasteboardType, Data)] = [] - let currentItems = pasteboard.pasteboardItems ?? [] - for item in currentItems { - for type in item.types { - if let data = item.data(forType: type) { - savedContents.append((type, data)) + if shouldPreserveClipboard { + let currentItems = pasteboard.pasteboardItems ?? [] + + for item in currentItems { + for type in item.types { + if let data = item.data(forType: type) { + savedContents.append((type, data)) + } } } } @@ -31,8 +34,8 @@ class CursorPaster { pasteUsingCommandV() } - DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + pasteCompletionDelay) { - if !savedContents.isEmpty { + if shouldPreserveClipboard && !savedContents.isEmpty { + DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + pasteCompletionDelay) { pasteboard.clearContents() for (type, data) in savedContents { pasteboard.setData(data, forType: type) diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index 27ce581..9d7a853 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -362,15 +362,7 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { SoundManager.shared.playStopSound() if AXIsProcessTrusted() { DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { - CursorPaster.pasteAtCursor(text) - } - } - if isAutoCopyEnabled { - let success = ClipboardManager.copyToClipboard(text) - if success { - clipboardMessage = "Transcription copied to clipboard" - } else { - clipboardMessage = "Failed to copy to clipboard" + CursorPaster.pasteAtCursor(text, shouldPreserveClipboard: !self.isAutoCopyEnabled) } } try? FileManager.default.removeItem(at: url)