Repository navigation
fix: mark the document dirty for guides, comps and saved selections - #44
Conversation
IAmJSD
left a comment
There was a problem hiding this comment.
Had some concerns about this PR, so gave it to Fable with my concerns, here's what it said:
Review of ProdigyRahul:fix/dirty-flag-document-state is done, and your gut was right: the fix is inconsistent. Seven findings are reported above; here's the shape of it.
The core inconsistency. A census of every non-test site that mutates the affected collections shows the PR covers 7 of 12. What it missed is the entire plugins/tools-doc plugin — the Note, Count, Artboard, and Slice tools that create and move this state only call add_damage, and the PR's own new test proves damage doesn't set dirty. So the fix covers destruction (the Clear menu items) but not creation: place ten notes or drag out export slices on a saved document, close the tab, and you still get no prompt and autosave still skips it — the exact bug the PR describes, unfixed for its most common entry point. The inconsistency is even visible inside one match: the Frame variant of the rect tool commits through begin_edit and gets dirty for free, while the Artboard and Slice arms right next to it don't.
It also errs in the opposite direction. clear_guides, ClearNotes, and ClearCounts mark dirty unconditionally, so clearing an already-empty list flags an unchanged document — spurious close prompt, plus a full codec export to disk every 30 seconds from autosave until the next manual save. An is_empty() guard at those three sites fixes it.
Two deeper problems worth flagging on the PR:
- No codec in the repo serializes guides, layer comps, saved selections, notes, or counts. So the new prompt's "Save" button writes a file that omits the very state that made the document dirty, clears the flag, and closes the tab as if it were safe. The protection the PR adds is partly hollow until the exporters carry this state (autosave recovery snapshots have the same gap, and Cmd-Q bypasses the dirty check entirely — both pre-existing, but they bound what this fix actually buys).
- Structurally, the per-call-site approach can't be enforced: the fields stay
pub, two pre-existingdoc.dirty = truewrites weren't migrated to the new helper, and the PR's own doc comment concedes these lists belong in the edit history.EditOp::SelectionSetis a ready-made template — routing these mutations through edit ops would set dirty centrally and make them undoable, closing the class of bug instead of six instances of it.
On the plus side: the seven sites it did cover were each verified correct (live consumers, no indicator lag, no double-marking through the command dispatch), and both new test suites pass in the review worktree — though the mark_dirty unit test is tautological and would stay green even with every call site deleted.
My recommendation for the PR author: at minimum extend the fix to the tools-doc sites and guard the three clears; ideally replace the scattered calls with edit ops. And it's worth an honest note on the PR that save/autosave can't yet persist most of this state.
|
thanks, and fable was right on both counts. fixed and pushed. covered the creation side. every frame stays untouched there because guarded the three clears. the tautological test is gone. it now says what it pins, which is the helper's contract only. the call sites are covered where they live, in on the two deeper points, you are right and i am not fixing them here. no codec serializes guides, comps, saved selections, notes or counts. so save still writes a file without the state that made the document dirty. this pr stops the silent loss on close and gets the document into autosave, it does not make the save complete. same gap in the recovery snapshots, and cmd-q still bypasses the check. and the per call site approach cannot be enforced while the fields are
|
IAmJSD
left a comment
There was a problem hiding this comment.
Reviewed by Claude (Fable 5) on Astrid's behalf. Traced every direct-mutation site of guides/comps/saved selections/notes/counts at this revision — all covered, no incorrect markings, and the tests fail on main as they should. The no-op guards on the clear paths are a nice touch. Merging.
fixes #43
add
Document::mark_dirtyand call it from the seven sites that mutate document state outsidebegin_edit. that is enough for the close prompt to appear and for autosave to stop skipping the document.a named method rather than
doc.dirty = truescattered around, so the next such mutation has an obvious thing to call and the doc comment explains why it exists. those lists still belong in history; when they get their ownEditOpthis call becomes redundant rather than wrong, and the comment says so.the regression test is at the call site, not on the setter: it runs
select.savethrough the real command registry and asserts the document comes back dirty. it fails on main withand the document must count as unsaved. a second test pins thatadd_damagealone does not imply unsaved changes, since that is the trap that makes this look already-handled.579 tests pass, clippy and fmt clean.