Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more
fix: harden Paste Last Transcription against edge cases (self-review)
Tom08ba816869a6
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swiftindex 6021711b..e9d34977 100644--- a/Sources/Fluid/ContentView.swift+++ b/Sources/Fluid/ContentView.swift@@ -2532,8 +2532,19 @@ struct ContentView: View {// physically held. Synthesizing text in that state makes the target app treat the// characters as keyboard shortcuts and drop them, so wait for the modifiers to be// released before inserting. (Dictation never hits this because by the time it types,- // no keys are held.)- await Self.waitForHotkeyModifiersReleased(timeout: 0.6)+ // no keys are held.) If they never release (stuck/held), abort rather than typing a+ // corrupted — and possibly destructive — shortcut sequence; the user can retrigger.+ guard await Self.waitForHotkeyModifiersReleased(timeout: 0.6) else {+ DebugLogger.shared.info("Actions: Paste aborted - modifier keys still held", source: "ContentView")+ return+ }++ // Re-check here rather than only at the hotkey trigger: the overlay menu entry point+ // has no pre-check, and the wait above may have elapsed since the trigger fired.+ guard !self.asr.isRunning else {+ DebugLogger.shared.info("Actions: Paste skipped - recording in progress", source: "ContentView")+ return+ }let typingTarget = self.resolveTypingTargetPID()guard typingTarget.pid != nil else {@@ -2548,18 +2559,20 @@ struct ContentView: View {}}- /// Polls until the keyboard modifier keys are released (or the timeout elapses). Used before- /// synthesizing a paste so the inserted characters aren't swallowed as modifier+key shortcuts.- private static func waitForHotkeyModifiersReleased(timeout: TimeInterval) async {+ /// Polls until the keyboard modifier keys are released, returning `true` once they are, or+ /// `false` if the timeout elapses with keys still held. Used before synthesizing a paste so the+ /// inserted characters aren't swallowed as modifier+key shortcuts.+ private static func waitForHotkeyModifiersReleased(timeout: TimeInterval) async -> Bool {let relevant: CGEventFlags = [.maskCommand, .maskControl, .maskAlternate, .maskShift, .maskSecondaryFn]let start = Date()while Date().timeIntervalSince(start) < timeout {let flags = CGEventSource.flagsState(.combinedSessionState)if flags.isDisjoint(with: relevant) {- return+ return true}try? await Task.sleep(nanoseconds: 15_000_000) // 15ms}+ return false}private func undoLastAIProcessingFromHistory() {diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swiftindex 1325226a..a1ed50b8 100644--- a/Sources/Fluid/Persistence/SettingsStore.swift+++ b/Sources/Fluid/Persistence/SettingsStore.swift@@ -2855,7 +2855,11 @@ final class SettingsStore: ObservableObject {self.rewriteModeSelectedProviderID = payload.rewriteModeSelectedProviderIDself.rewriteModeLinkedToGlobal = payload.rewriteModeLinkedToGlobalself.cancelRecordingHotkeyShortcut = payload.cancelRecordingHotkeyShortcut- self.pasteLastTranscriptionHotkeyShortcut = payload.pasteLastTranscriptionHotkeyShortcut+ // Both guarded so restoring an older backup (which predates these fields) doesn't wipe a+ // currently-configured shortcut or leave the feature enabled with no shortcut bound.+ if let pasteLastTranscriptionHotkeyShortcut = payload.pasteLastTranscriptionHotkeyShortcut {+ self.pasteLastTranscriptionHotkeyShortcut = pasteLastTranscriptionHotkeyShortcut+ }if let pasteLastTranscriptionShortcutEnabled = payload.pasteLastTranscriptionShortcutEnabled {self.pasteLastTranscriptionShortcutEnabled = pasteLastTranscriptionShortcutEnabled}diff --git a/Sources/Fluid/Services/GlobalHotkeyManager.swift b/Sources/Fluid/Services/GlobalHotkeyManager.swiftindex bfee8d2b..6a260411 100644--- a/Sources/Fluid/Services/GlobalHotkeyManager.swift+++ b/Sources/Fluid/Services/GlobalHotkeyManager.swift@@ -659,7 +659,10 @@ final class GlobalHotkeyManager: NSObject {let pasteShortcut = SettingsStore.shared.pasteLastTranscriptionHotkeyShortcut,pasteShortcut.matches(keyCode: keyCode, modifiers: eventModifiers){- self.triggerPasteLastTranscription()+ // Holding the chord emits auto-repeat key-downs; because the paste waits for the+ // modifiers to release, every repeat would otherwise queue another insertion and+ // paste N times. triggerPasteLastTranscription ignores repeats.+ self.triggerPasteLastTranscription(isAutorepeat: event.getIntegerValueField(.keyboardEventAutorepeat) != 0)return nil}@@ -1666,9 +1669,11 @@ final class GlobalHotkeyManager: NSObject {}}- private func triggerPasteLastTranscription() {+ private func triggerPasteLastTranscription(isAutorepeat: Bool) {Task { @MainActor [weak self] inguard let self = self else { return }+ // Holding the chord auto-repeats the key-down; act only on the initial press.+ guard !isAutorepeat else { return }guard self.canTriggerRecordingAction("Paste last transcription hotkey") else { return }// Re-pasting mid-recording would be surprising; ignore while capture is active.guard !self.asrService.isRunning else {