Crash-Haertung: Delegat bei Programm-Sets abhaengen, send()-Pointer safe, Doku
This commit is contained in:
@@ -205,12 +205,13 @@ final class PTYSession: ObservableObject {
|
||||
func send(_ string: String) {
|
||||
let fd = masterFD
|
||||
guard fd >= 0 else { return }
|
||||
guard let data = string.data(using: .utf8) else { return }
|
||||
guard let data = string.data(using: .utf8), !data.isEmpty else { return }
|
||||
ioQueue.async {
|
||||
data.withUnsafeBytes { ptr in
|
||||
guard let base = ptr.baseAddress else { return }
|
||||
var written = 0
|
||||
while written < data.count {
|
||||
let n = write(fd, ptr.baseAddress!.advanced(by: written), data.count - written)
|
||||
let n = write(fd, base.advanced(by: written), data.count - written)
|
||||
if n <= 0 { break }
|
||||
written += n
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user