Skip to content

fix: collapse the empty text layer discard instead of undoing blindly - #46

Merged
IAmJSD merged 1 commit into
Infrawrench:mainfrom
ProdigyRahul:fix/type-discard-empty-undo
Aug 27, 2026
Merged

IAmJSD merged 1 commit into
Infrawrench:mainfrom
ProdigyRahul:fix/type-discard-empty-undo

Conversation

@ProdigyRahul

@ProdigyRahul ProdigyRahul commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

fixes #45

add History::drop_cancelling_pair, which removes the newest two undo entries only when they are exactly the pair named, and use it to collapse the insert and its removal. nothing is dropped unless both are still on top, so an edit committed in between is never touched.

the old code could not be right either way: undo() unwinds whatever is on top rather than this layer's own insert, and pop_redo() is the redo primitive, so it pushed the junk back onto the undo stack instead of discarding it.

the regression test commits a real edit while the empty session is open, which is the case that actually loses data. it fails on main with the edit made during the session must survive: ["bg", "Text"] — the user's layer gone, the empty text layer still there.

578 tests pass, clippy and fmt clean.

before

the levels layer made during the empty session is gone; the empty text layer stayed.

before

after

the levels layer survives; the empty text layer is discarded.

after

@ProdigyRahul

Copy link
Copy Markdown
Contributor Author

@IAmJSD

@IAmJSD

IAmJSD commented Aug 27, 2026

Copy link
Copy Markdown
Member

I've seen. Whilst I do appreciate your PRs, they take time to review.

@IAmJSD IAmJSD left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by Claude (Fable 5) on Astrid's behalf. Confirmed the old path double-undid arbitrary edits and misused pop_redo (pushing unwound entries back without re-applying), and that the new name-guarded pair-drop is conservative — an interleaved edit leaves both entries honestly in history. Both regression tests fail on main. One future-proofing note, non-blocking: drop_cancelling_pair matches by display name; matching on the insert op's LayerId would make it robust if another code path ever commits an edit named "New Text Layer". Merging.

@IAmJSD
IAmJSD merged commit 36171b6 into Infrawrench:main Aug 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clicking with the type tool without typing reverts the last two real edits

2 participants