Skip to content

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(typing): ignore paste read-back after user input

altic-dev788d04b67179
diff --git a/Sources/Fluid/Services/PasteVerifier.swift b/Sources/Fluid/Services/PasteVerifier.swift
index 5dd677e9..f1887232 100644
--- a/Sources/Fluid/Services/PasteVerifier.swift
+++ b/Sources/Fluid/Services/PasteVerifier.swift
@@ -74,6 +74,20 @@ enum PasteVerifier {
static let finalCheckDelay: TimeInterval = 1.0
static var totalDecisionDelay: TimeInterval { self.firstCheckDelay + self.secondCheckDelay + self.finalCheckDelay }
+ /// A key press or click after the paste means the user acted on the field
+ /// (typically Return to send), so an unchanged field proves nothing.
+ nonisolated static func userActedAfterPaste(secondsSinceLastInput: TimeInterval, secondsSincePaste: TimeInterval) -> Bool {
+ // Our own synthesized V key lands at the paste instant; ignore that window.
+ secondsSinceLastInput < secondsSincePaste - 0.05
+ }
+
+ nonisolated static func secondsSinceLastUserInput() -> TimeInterval {
+ min(
+ CGEventSource.secondsSinceLastEventType(.hidSystemState, eventType: .keyDown),
+ CGEventSource.secondsSinceLastEventType(.hidSystemState, eventType: .leftMouseDown)
+ )
+ }
+
/// Call off the main thread after the paste command was posted.
nonisolated static func verify(before: Snapshot, pastedText: String) async -> Verdict {
let needle = self.normalize(pastedText)
diff --git a/Sources/Fluid/Services/TypingService.swift b/Sources/Fluid/Services/TypingService.swift
index 1bd569fd..4f26acca 100644
--- a/Sources/Fluid/Services/TypingService.swift
+++ b/Sources/Fluid/Services/TypingService.swift
@@ -698,7 +698,13 @@ final class TypingService {
private func verifyPasteLanded(_ text: String, before: PasteVerifier.Snapshot) {
Task.detached(priority: .utility) {
let startedAt = ProcessInfo.processInfo.systemUptime
- let verdict = await PasteVerifier.verify(before: before, pastedText: text)
+ var verdict = await PasteVerifier.verify(before: before, pastedText: text)
+ if case .notLanded = verdict, PasteVerifier.userActedAfterPaste(
+ secondsSinceLastInput: PasteVerifier.secondsSinceLastUserInput(),
+ secondsSincePaste: ProcessInfo.processInfo.systemUptime - startedAt
+ ) {
+ verdict = .unknown(reason: "user_input_after_paste")
+ }
let app = NSRunningApplication(processIdentifier: before.pid)?.bundleIdentifier ?? "pid\(before.pid)"
DebugLogger.shared.info(
"PASTE_VERIFY \(verdict.logDescription) app=\(app) before[\(before.summary)] " +
diff --git a/Tests/FluidDictationIntegrationTests/SpokenSendTests.swift b/Tests/FluidDictationIntegrationTests/SpokenSendTests.swift
index ac65e6e0..baa18a06 100644
--- a/Tests/FluidDictationIntegrationTests/SpokenSendTests.swift
+++ b/Tests/FluidDictationIntegrationTests/SpokenSendTests.swift
@@ -362,6 +362,23 @@ final class SpokenSendTests: XCTestCase {
}
}
+ // MARK: - Paste read-back after a fast manual send
+
+ func testReadBackStandsDownWhenUserActsAfterPaste() {
+ // Return pressed 0.4 s after the paste; the verdict arrives at 1.5 s.
+ XCTAssertTrue(PasteVerifier.userActedAfterPaste(secondsSinceLastInput: 1.1, secondsSincePaste: 1.5))
+ // Return pressed almost immediately.
+ XCTAssertTrue(PasteVerifier.userActedAfterPaste(secondsSinceLastInput: 1.4, secondsSincePaste: 1.5))
+ }
+
+ func testReadBackStillReportsWhenNothingHappenedSinceThePaste() {
+ // The last input is our own synthesized V at the paste instant.
+ XCTAssertFalse(PasteVerifier.userActedAfterPaste(secondsSinceLastInput: 1.5, secondsSincePaste: 1.5))
+ XCTAssertFalse(PasteVerifier.userActedAfterPaste(secondsSinceLastInput: 1.48, secondsSincePaste: 1.5))
+ // The last input was long before the paste.
+ XCTAssertFalse(PasteVerifier.userActedAfterPaste(secondsSinceLastInput: 30, secondsSincePaste: 1.5))
+ }
+
func testImmediateStopCompletionRequiresTerminalPhraseAndSilence() {
let arguments = (
text: "Ready, send it.",