Crash-Haertung: Delegat bei Programm-Sets abhaengen, send()-Pointer safe, Doku

This commit is contained in:
x3
2026-09-21 23:52:23 +02:00
parent ed6e96b3c1
commit 69f9e9952c
3 changed files with 27 additions and 4 deletions
@@ -38,10 +38,19 @@ struct TerminalInputField: NSViewRepresentable {
func updateNSView(_ view: NSView, context: Context) {
context.coordinator.onSubmit = onSubmit
if let f = view as? NSTextField, f.stringValue != text {
f.stringValue = text
// Delegat während Programm-Sets abhängen: sonst feuert textDidChange synchron
// zurück ins SwiftUI-State — mitten im Render -> Crash ("Modifying state
// during view update"). User-Tippen läuft weiter über den Delegaten.
if let f = view as? NSTextField {
if f.stringValue != text {
f.delegate = nil
f.stringValue = text
f.delegate = context.coordinator
}
} else if let tv = view as? NSTextView, tv.string != text {
tv.delegate = nil
tv.string = text
tv.delegate = context.coordinator
}
}