diff --git a/VoiceInk/CursorPaster.swift b/VoiceInk/CursorPaster.swift index c954c0f..b99a0ce 100644 --- a/VoiceInk/CursorPaster.swift +++ b/VoiceInk/CursorPaster.swift @@ -2,21 +2,18 @@ import Foundation import AppKit class CursorPaster { - private static let pasteCompletionDelay: TimeInterval = 0.6 - static func pasteAtCursor(_ text: String, shouldPreserveClipboard: Bool = true) { + static func pasteAtCursor(_ text: String) { let pasteboard = NSPasteboard.general var savedContents: [(NSPasteboard.PasteboardType, 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)) - } + let currentItems = pasteboard.pasteboardItems ?? [] + + for item in currentItems { + for type in item.types { + if let data = item.data(forType: type) { + savedContents.append((type, data)) } } } @@ -30,11 +27,14 @@ class CursorPaster { pasteUsingCommandV() } - if shouldPreserveClipboard && !savedContents.isEmpty { - DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + pasteCompletionDelay) { - pasteboard.clearContents() - for (type, data) in savedContents { - pasteboard.setData(data, forType: type) + DispatchQueue.main.asyncAfter(deadline: .now() + 0.075) { + pasteboard.clearContents() + + if !savedContents.isEmpty { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + for (type, data) in savedContents { + pasteboard.setData(data, forType: type) + } } } } diff --git a/VoiceInk/Services/LastTranscriptionService.swift b/VoiceInk/Services/LastTranscriptionService.swift index 35dbff3..d6ef0cf 100644 --- a/VoiceInk/Services/LastTranscriptionService.swift +++ b/VoiceInk/Services/LastTranscriptionService.swift @@ -67,7 +67,7 @@ class LastTranscriptionService: ObservableObject { // Delay to give the user time to release modifier keys (especially Control) DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) { - CursorPaster.pasteAtCursor(textToPaste + " ", shouldPreserveClipboard: true) + CursorPaster.pasteAtCursor(textToPaste + " ") } } diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index c93bef3..f6364b6 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -359,7 +359,7 @@ class WhisperState: NSObject, ObservableObject { DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { - CursorPaster.pasteAtCursor(text, shouldPreserveClipboard: true) + CursorPaster.pasteAtCursor(text) let powerMode = PowerModeManager.shared if let activeConfig = powerMode.currentActiveConfiguration, activeConfig.isAutoSendEnabled {