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

feat(dictation): make starting-field restoration optional

altic-devadf0216ec75f
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index 8138f999..8f778466 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -2126,23 +2126,26 @@ struct ContentView: View {
self.captureRecordingFormattingContextIfNeeded()
}
- private func resolveTypingTargetPID() -> (pid: pid_t?, shouldRestoreOriginalFocus: Bool) {
+ private func resolveTypingTargetPID(returnToStartingField: Bool = true) -> (pid: pid_t?, shouldRestoreOriginalFocus: Bool) {
let startedAt = ProcessInfo.processInfo.systemUptime
- guard let context = NotchContentState.shared.recordingTargetContext else {
- self.appBench("focus_target_check totalMs=\((ProcessInfo.processInfo.systemUptime - startedAt) * 1000) missingContext=true")
- return (NotchContentState.shared.recordingTargetPID, true)
- }
- let pidStartedAt = ProcessInfo.processInfo.systemUptime
+ let context = NotchContentState.shared.recordingTargetContext
let focusedPID = TypingService.currentFocusedPID()
let pidFinishedAt = ProcessInfo.processInfo.systemUptime
- let checksElement = context.pid == focusedPID && context.element != nil
- let elementIsFocused = !checksElement || TypingService.isCapturedFocusStillActive(context)
+ let checksElement = returnToStartingField && context?.pid == focusedPID && context?.element != nil
+ let elementIsFocused = !checksElement || context.map { TypingService.isCapturedFocusStillActive($0) } == true
+ let target = DictationTargetPolicy.resolve(
+ returnToStartingField: returnToStartingField,
+ focusedPID: focusedPID,
+ ownPID: ProcessInfo.processInfo.processIdentifier,
+ originalPID: context?.pid ?? NotchContentState.shared.recordingTargetPID,
+ originalFieldIsFocused: context != nil && context?.pid == focusedPID && elementIsFocused
+ )
let finishedAt = ProcessInfo.processInfo.systemUptime
self.appBench(
- "focus_target_check totalMs=\((finishedAt - startedAt) * 1000) pidMs=\((pidFinishedAt - pidStartedAt) * 1000) " +
- "elementMs=\((finishedAt - pidFinishedAt) * 1000) elementChecked=\(checksElement)"
+ "focus_target_check totalMs=\((finishedAt - startedAt) * 1000) pidMs=\((pidFinishedAt - startedAt) * 1000) " +
+ "elementMs=\((finishedAt - pidFinishedAt) * 1000) elementChecked=\(checksElement) returnToStartingField=\(returnToStartingField)"
)
- return (context.pid, !(context.pid == focusedPID && elementIsFocused))
+ return target
}
// MARK: - Commented out app-specific prompts - using general processing only
@@ -2901,7 +2904,7 @@ struct ContentView: View {
)
if shouldTypeExternally {
- let typingTarget = self.resolveTypingTargetPID()
+ let typingTarget = self.resolveTypingTargetPID(returnToStartingField: self.settings.returnDictationToStartingField)
let spokenSendRequested = spokenSendParse.shouldSend
let targetMatchesRecordingFocus = typingTarget.pid != nil
&& typingTarget.pid == self.recordingFocusTarget?.pid
@@ -2909,6 +2912,7 @@ struct ContentView: View {
&& aiFallbackReason == nil
&& (sendsExistingDraft || !finalText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
&& targetMatchesRecordingFocus
+ && (typingTarget.shouldRestoreOriginalFocus || self.recordingFocusTarget.map { TypingService.isExactFocusTargetActive($0) } == true)
&& !self.isSpokenSendBlockedApp(appInfo)
// Dispatch insertion as soon as the destination app is ready; the
// overlay hides asynchronously after output so it cannot delay paste.
diff --git a/Sources/Fluid/Persistence/BackupService.swift b/Sources/Fluid/Persistence/BackupService.swift
index 0dfdd165..6e703f32 100644
--- a/Sources/Fluid/Persistence/BackupService.swift
+++ b/Sources/Fluid/Persistence/BackupService.swift
@@ -60,6 +60,8 @@ struct SettingsBackupPayload: Codable, Equatable {
let enableStreamingPreview: Bool
// Optional so backups created before incremental Parakeet finalization still decode.
let experimentalParakeetUnifiedFinalEnabled: Bool?
+ // Optional to preserve compatibility with older backups.
+ let returnDictationToStartingField: Bool?
// Optional so backups created before History performance details still decode.
let showHistoryPerformanceMetrics: Bool?
// Optional so backups created before the silence filter still decode.
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swift
index d893a2e7..8de7aac4 100644
--- a/Sources/Fluid/Persistence/SettingsStore.swift
+++ b/Sources/Fluid/Persistence/SettingsStore.swift
@@ -1851,6 +1851,15 @@ final class SettingsStore: ObservableObject {
}
}
+ /// Opt in to restoring the field captured at recording start.
+ var returnDictationToStartingField: Bool {
+ get { self.defaults.bool(forKey: Keys.returnDictationToStartingField) }
+ set {
+ objectWillChange.send()
+ self.defaults.set(newValue, forKey: Keys.returnDictationToStartingField)
+ }
+ }
+
/// Shows ASR and AI performance details by default; users can hide them.
var showHistoryPerformanceMetrics: Bool {
get { self.defaults.object(forKey: Keys.showHistoryPerformanceMetrics) as? Bool ?? true }
@@ -3304,6 +3313,7 @@ final class SettingsStore: ObservableObject {
hotkeyMode: self.hotkeyMode,
enableStreamingPreview: self.enableStreamingPreview,
experimentalParakeetUnifiedFinalEnabled: self.experimentalParakeetUnifiedFinalEnabled,
+ returnDictationToStartingField: self.returnDictationToStartingField,
showHistoryPerformanceMetrics: self.showHistoryPerformanceMetrics,
skipSilentRecordingsEnabled: self.skipSilentRecordingsEnabled,
enableAIStreaming: self.enableAIStreaming,
@@ -3439,6 +3449,9 @@ final class SettingsStore: ObservableObject {
if let experimentalParakeetUnifiedFinalEnabled = payload.experimentalParakeetUnifiedFinalEnabled {
self.experimentalParakeetUnifiedFinalEnabled = experimentalParakeetUnifiedFinalEnabled
}
+ if let returnDictationToStartingField = payload.returnDictationToStartingField {
+ self.returnDictationToStartingField = returnDictationToStartingField
+ }
if let showHistoryPerformanceMetrics = payload.showHistoryPerformanceMetrics {
self.showHistoryPerformanceMetrics = showHistoryPerformanceMetrics
}
@@ -5459,6 +5472,7 @@ private extension SettingsStore {
static let hotkeyMode = "HotkeyMode"
static let enableStreamingPreview = "EnableStreamingPreview"
static let experimentalParakeetUnifiedFinalEnabled = "ExperimentalParakeetUnifiedFinalEnabled"
+ static let returnDictationToStartingField = "ReturnDictationToStartingField"
static let showHistoryPerformanceMetrics = "ShowHistoryPerformanceMetrics"
static let skipSilentRecordingsEnabled = "SkipSilentRecordingsEnabled"
static let enableAIStreaming = "EnableAIStreaming"
diff --git a/Sources/Fluid/Services/DictationTargetPolicy.swift b/Sources/Fluid/Services/DictationTargetPolicy.swift
new file mode 100644
index 00000000..456195bc
--- /dev/null
+++ b/Sources/Fluid/Services/DictationTargetPolicy.swift
@@ -0,0 +1,20 @@
+import Foundation
+
+/// Ordinary dictation may follow the current cursor. Rewrite and retry callers
+/// retain their captured destination unless they explicitly opt into this policy.
+enum DictationTargetPolicy {
+ static func resolve(
+ returnToStartingField: Bool,
+ focusedPID: Int32?,
+ ownPID: Int32,
+ originalPID: Int32?,
+ originalFieldIsFocused: Bool
+ ) -> (pid: Int32?, shouldRestoreOriginalFocus: Bool) {
+ if !returnToStartingField, let focusedPID, focusedPID > 0, focusedPID != ownPID {
+ return (focusedPID, false)
+ }
+ // An app-owned overlay may temporarily hold focus. Recover the saved
+ // field in that case, rather than treating the overlay as a destination.
+ return (originalPID, !originalFieldIsFocused)
+ }
+}
diff --git a/Sources/Fluid/UI/SettingsSearch.swift b/Sources/Fluid/UI/SettingsSearch.swift
index 83767ca7..6d2a1bbe 100644
--- a/Sources/Fluid/UI/SettingsSearch.swift
+++ b/Sources/Fluid/UI/SettingsSearch.swift
@@ -61,6 +61,7 @@ enum SettingsSearchTarget: Hashable {
case audioStorage
case debugLogs
case experimental
+ case returnToStartingField
case fasterLongDictation
case historyPerformance
@@ -117,7 +118,7 @@ enum SettingsSearchTarget: Hashable {
case .dataAndDiagnostics, .backupAndRestore, .debugLogs:
return .dataAndDiagnostics
- case .experimental, .fasterLongDictation, .historyPerformance:
+ case .experimental, .returnToStartingField, .fasterLongDictation, .historyPerformance:
return .experimental
}
}
@@ -354,6 +355,11 @@ enum SettingsSearchIndex {
title: "Debug Settings",
terms: ["Show Debug Logs in App Reveal Log File crash diagnostics troubleshooting"]
),
+ .init(
+ target: .returnToStartingField,
+ title: "Return to Starting Field",
+ terms: ["experimental dictation paste cursor focus original starting app destination switch apps"]
+ ),
.init(
target: .fasterLongDictation,
title: "Faster Long Dictation",
diff --git a/Sources/Fluid/UI/SettingsView.swift b/Sources/Fluid/UI/SettingsView.swift
index f4934eb4..d5ff535c 100644
--- a/Sources/Fluid/UI/SettingsView.swift
+++ b/Sources/Fluid/UI/SettingsView.swift
@@ -1524,6 +1524,10 @@ struct SettingsView: View {
ThemedCard(style: .standard) {
VStack(alignment: .leading, spacing: 14) {
+ self.returnToStartingFieldToggle
+
+ Divider().padding(.vertical, 4)
+
self.settingsToggleRow(
title: "Faster Long Dictation",
description: "For long recordings, reuse completed live windows and process only the remaining tail when you stop.",
@@ -3042,3 +3046,18 @@ struct AnalyticsConfirmationView: View {
.frame(width: 420)
}
}
+
+private extension SettingsView {
+ var returnToStartingFieldToggle: some View {
+ self.settingsToggleRow(
+ title: "Return to Starting Field",
+ description: "Paste dictation into the field where you started recording, even if you switch apps.",
+ footnote: "Off by default. When off, dictation follows your current cursor. Applies to dictation only.",
+ isOn: Binding(
+ get: { SettingsStore.shared.returnDictationToStartingField },
+ set: { SettingsStore.shared.returnDictationToStartingField = $0 }
+ )
+ )
+ .settingsSearchTarget(.returnToStartingField)
+ }
+}
diff --git a/Tests/DictationTargetPolicyTests.swift b/Tests/DictationTargetPolicyTests.swift
new file mode 100644
index 00000000..307b68b7
--- /dev/null
+++ b/Tests/DictationTargetPolicyTests.swift
@@ -0,0 +1,27 @@
+import Foundation
+
+@main
+enum DictationTargetPolicyTests {
+ static func main() {
+ let cases: [(String, Bool, Int32?, Int32?, Bool, Int32?, Bool)] = [
+ ("off follows app B", false, 200, 100, false, 200, false),
+ ("on restores app A", true, 200, 100, false, 100, true),
+ ("off follows another field in A", false, 100, 100, false, 100, false),
+ ("on restores original field in A", true, 100, 100, false, 100, true),
+ ("already focused needs no restore", true, 100, 100, true, 100, false),
+ ("off works without recording context", false, 200, nil, false, 200, false),
+ ("overlay recovers saved target", false, 999, 100, false, 100, true),
+ ("unknown focus recovers saved target", false, nil, 100, false, 100, true),
+ ("invalid focus is not a destination", false, 0, 100, false, 100, true),
+ ("missing target does not invent a PID", true, nil, nil, false, nil, true),
+ ]
+ for (name, enabled, focused, original, stillFocused, expectedPID, restores) in cases {
+ let result = DictationTargetPolicy.resolve(
+ returnToStartingField: enabled, focusedPID: focused, ownPID: 999,
+ originalPID: original, originalFieldIsFocused: stillFocused
+ )
+ precondition(result.pid == expectedPID && result.shouldRestoreOriginalFocus == restores, name)
+ }
+ print("PASS: \(cases.count) dictation destination cases, including app switches, field switches, overlays and missing focus")
+ }
+}
diff --git a/scripts/test_dictation_target.sh b/scripts/test_dictation_target.sh
new file mode 100644
index 00000000..b048cd6c
--- /dev/null
+++ b/scripts/test_dictation_target.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -eu
+cd "$(dirname "$0")/.."
+task_developer_dir="${DEVELOPER_DIR:-$(xcode-select -p)}"
+test -d "$task_developer_dir/Platforms/MacOSX.platform"
+export DEVELOPER_DIR="$task_developer_dir"
+task_test_dir=$(mktemp -d /tmp/fluidvoice-target-tests.XXXXXX)
+trap 'rm -rf "$task_test_dir"' EXIT
+xcrun swiftc -O -parse-as-library Sources/Fluid/Services/DictationTargetPolicy.swift Tests/DictationTargetPolicyTests.swift -o "$task_test_dir/tests"
+"$task_test_dir/tests"