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 the prompt rendering on first load
grohith327d56676bcfba2
diff --git a/Sources/Fluid/UI/AISettingsView.swift b/Sources/Fluid/UI/AISettingsView.swiftindex e4edb126..25af4992 100644--- a/Sources/Fluid/UI/AISettingsView.swift+++ b/Sources/Fluid/UI/AISettingsView.swift@@ -85,6 +85,7 @@ struct AISettingsView: View {@State private var editingPromptID: String? = nil@State private var draftPromptName: String = ""@State private var draftPromptText: String = ""+ @State private var promptEditorSessionID: UUID = UUID()var body: some View {ScrollView(.vertical, showsIndicators: false) {@@ -1648,10 +1649,13 @@ struct AISettingsView: View {Text("Prompt").font(.caption).foregroundStyle(.secondary)- TextEditor(text: self.$draftPromptText)- .font(.system(.caption, design: .monospaced))+ PromptTextView(+ text: self.$draftPromptText,+ isEditable: !self.editorIsDefaultPrompt,+ font: NSFont.monospacedSystemFont(ofSize: NSFont.smallSystemFontSize, weight: .regular)+ )+ .id(self.promptEditorSessionID).frame(minHeight: 180)- .scrollContentBackground(.hidden).background(RoundedRectangle(cornerRadius: 8, style: .continuous).fill(.ultraThinMaterial.opacity(0.25))@@ -1660,7 +1664,6 @@ struct AISettingsView: View {.stroke(.white.opacity(0.12), lineWidth: 1)))- .disabled(self.editorIsDefaultPrompt).onChange(of: self.draftPromptText) { _, newValue inself.promptTest.updateDraftPromptText(newValue)}@@ -1803,6 +1806,7 @@ struct AISettingsView: View {self.editingPromptID = nilself.draftPromptName = "Default"self.draftPromptText = self.defaultDictationPromptText()+ self.promptEditorSessionID = UUID()self.showingPromptEditor = true}@@ -1811,6 +1815,7 @@ struct AISettingsView: View {self.editingPromptID = nilself.draftPromptName = "New Prompt"self.draftPromptText = ""+ self.promptEditorSessionID = UUID()self.showingPromptEditor = true}@@ -1819,6 +1824,7 @@ struct AISettingsView: View {self.editingPromptID = profile.idself.draftPromptName = profile.nameself.draftPromptText = profile.prompt+ self.promptEditorSessionID = UUID()self.showingPromptEditor = true}diff --git a/Sources/Fluid/UI/PromptTextView.swift b/Sources/Fluid/UI/PromptTextView.swiftnew file mode 100644index 00000000..70a715d9--- /dev/null+++ b/Sources/Fluid/UI/PromptTextView.swift@@ -0,0 +1,76 @@+import AppKit+import SwiftUI++/// A lightweight macOS-native text view that reliably renders bound text immediately,+/// avoiding occasional `TextEditor` refresh glitches in sheets.+struct PromptTextView: NSViewRepresentable {+ @Binding var text: String++ var isEditable: Bool = true+ var font: NSFont = .monospacedSystemFont(ofSize: NSFont.smallSystemFontSize, weight: .regular)++ func makeCoordinator() -> Coordinator {+ Coordinator(text: self.$text)+ }++ func makeNSView(context: Context) -> NSScrollView {+ let scrollView = NSScrollView()+ scrollView.hasVerticalScroller = true+ scrollView.drawsBackground = false+ scrollView.borderType = .noBorder++ let textView = NSTextView()+ textView.isRichText = false+ textView.usesRuler = false+ textView.allowsUndo = true+ textView.isEditable = self.isEditable+ textView.isSelectable = true+ textView.drawsBackground = false+ textView.font = self.font+ textView.delegate = context.coordinator++ textView.isVerticallyResizable = true+ textView.isHorizontallyResizable = false+ textView.autoresizingMask = [.width]+ textView.textContainer?.widthTracksTextView = true+ textView.textContainer?.containerSize = NSSize(width: scrollView.contentSize.width, height: .greatestFiniteMagnitude)++ textView.string = self.text++ scrollView.documentView = textView+ return scrollView+ }++ func updateNSView(_ nsView: NSScrollView, context: Context) {+ guard let textView = nsView.documentView as? NSTextView else { return }++ // Keep AppKit view in sync with SwiftUI state.+ // This is the critical bit that avoids "blank until focus changes" behavior.+ if textView.string != self.text {+ let selectedRanges = textView.selectedRanges+ textView.string = self.text+ textView.selectedRanges = selectedRanges+ }++ if textView.isEditable != self.isEditable { textView.isEditable = self.isEditable }+ textView.isSelectable = true+ textView.drawsBackground = false+ if textView.font != self.font { textView.font = self.font }+ }++ final class Coordinator: NSObject, NSTextViewDelegate {+ private var text: Binding<String>++ init(text: Binding<String>) {+ self.text = text+ }++ func textDidChange(_ notification: Notification) {+ guard let textView = notification.object as? NSTextView else { return }+ if self.text.wrappedValue != textView.string {+ self.text.wrappedValue = textView.string+ }+ }+ }+}+