fix(editor): normalize the guest watch's disk read

The external guest's watch read disk raw while the session's text and
lastFlushedText came through readDocument's normalizing external
branch, so diskTextChanged saw a difference on every BOM/CRLF file and
raised conflictAlert on unchanged content — re-arming after each
sibling directory event and after either alert answer, blocking
departures and quit until the user's own flush rewrote the file
normalized (finding museion/external-watch-compares-unnormalized-text,
argus cycle-6; unticketed, brief-32).

Extract the external branch (BOM strip + CRLF->LF) into
EditorSession.readExternalDocument(at:) — one shared normalizer, two
callers: the open read (readDocument) and the watch's onEvent. The #67
compare is now normalized-to-normalized; what readDocument loads is
unchanged.
This commit is contained in:
AlexKucera committed 2026-11-30 22:17:13 +01:00
1 parent b69ddd3963
commit 70dd47ed8c
2 files changed
+23 -9

No files matched your search

+6 -3
View File
@@ -62,11 +62,14 @@ extension PostsModel {
}
/// #93: watch the open external file — its rescan is the #67 disk-change
/// check, reused verbatim for foreign files. PostsWatcher fires on the
/// main actor already; no re-hop needed.
/// check, reused verbatim for foreign files. The disk read goes through
/// the shared external normalizer (brief-32): the session's text is
/// normalized on open, so a raw read raised a false conflict on every
/// directory event over an unchanged BOM/CRLF file. PostsWatcher fires
/// on the main actor already; no re-hop needed.
private func startExternalWatch(url: URL) {
externalWatcher.onEvent = { [weak self] in
guard let self, let session = externalSession, let disk = try? String(contentsOf: url, encoding: .utf8) else { return }
guard let self, let session = externalSession, let disk = EditorSession.readExternalDocument(at: url) else { return }
session.diskDidChange(diskText: disk)
}
externalWatcher.start(urls: [url.deletingLastPathComponent()])