fix(editor): guard document departure on failed flushes
teardown(flushFirst:) discarded flush()'s result, so document
navigation (newPost, newOutline, select, openExternal, dismissExternal,
openUnguarded) dropped the outgoing dirty session after a failed write
and replaced the only retained copy of the unsaved prose.
One shared departure gate now covers every site, placed before any
document-specific state clears:
- sessionMayDepart(_:): flushOrAbort's two gates (unanswered #67
conflict holds; failed flush holds) lifted to document departure —
flushOrAbort routes through it unchanged.
- dismissExternal() -> Bool: the guest departs only when its flush
lands; on failure the guest, its buffer, and its watcher stay live.
- departOpenDocuments(): the full-switch composition (guest + post
session) behind newPost/newOutline/openExternal.
- select/openUnguarded gate their same-id-conditional session teardowns
through sessionMayDepart directly.
Departure now aborts with the strip error set and the dirty session
retained; retrying after writability returns lands the edits and
completes the switch. All six PostsModelDepartureTests pins RED at
11b196d, GREEN with this change.
brief-25 [failed-flush-discarded-on-document-switch]
This commit is contained in:
1 parent
ecd14d1714
commit
250a662f3e
3 files changed
+70
-34
No files matched your search
@@ -66,10 +66,12 @@ extension PostsModel {
|
||||
/// #146: internal — `select` (PostsModel.swift) routes its tail through
|
||||
/// this one open body.
|
||||
func openUnguarded(_ id: String) {
|
||||
guard let home = watchedHome else { return }
|
||||
dismissExternal()
|
||||
guard let home = watchedHome, dismissExternal() else { return } // brief-25: the guest's edits land or the open aborts
|
||||
if let session, session.postID != id {
|
||||
session.teardown(flushFirst: true)
|
||||
// brief-25: a failed flush (or an unanswered #67 conflict)
|
||||
// aborts here — the dirty session stays up and honest.
|
||||
guard sessionMayDepart(session) else { return }
|
||||
session.teardown(flushFirst: false) // the gate already flushed
|
||||
}
|
||||
session = id == session?.postID ? session : EditorSession(postID: id, home: home)
|
||||
draft = nil
|
||||
|
||||
Reference in new issue
Block a user