Resolve a held save boundary to its live position before undoing to it - #101
Merged
Merged
Conversation
… to it [patch] Trimming replaced each SaveBoundary with a new object at the adjusted position, so a boundary a caller already held (from SaveBoundaryCreated, GetLastSaveBoundary or an earlier SaveBoundaries read) kept its old position. UndoToSaveBoundaryAsync and GetCommandsToUndo used that stale position as given and landed on an unsaved intermediate state. Adjusted boundaries now share an internal identity with the boundary they replace, and the service resolves its argument against the live boundaries. A boundary held across a trim undoes to its save point; one removed by branching or clearing is rejected. Fixes #88 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TX4nouJvSXNs7eSvDP13qU
…ale-save-boundary # Conflicts: # UndoRedo/Services/UndoRedoService.cs
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #88
What was wrong
When
MaxStackSizetrimmed the stack,SaveBoundaryManager.AdjustPositionsreplaced eachSaveBoundarywith a new object at the adjusted position. A caller could already be holding a boundary fromSaveBoundaryCreated,GetLastSaveBoundary(), or an earlier read ofSaveBoundaries. That boundary kept its old position, andUndoToSaveBoundaryAsyncandGetCommandsToUndoused it without checking. In the issue's repro, "revert to last save" left the document at value 2, an unsaved intermediate state, when the saved value was 1.Change
I took the stable-id option from the issue:
SaveBoundarygains an internal identity and an internal copy constructor.AdjustPositionsuses the copy constructor, so the boundary at the new position is still the same save point. The public shape ofSaveBoundaryis unchanged. The copy also keeps the originalTimestamp; before, a trim reset it to the time of the trim.UndoRedoService.UndoToSaveBoundaryAsyncandGetCommandsToUndofirst resolve their argument against the live boundaries. A boundary held across a trim resolves to its current position. A boundary whose save point no longer exists, because a branch orClear()removed it, makes the call returnfalseor an empty sequence, and nothing is undone.GetCurrentState()snapshot taken before a trim keeps the positions it was taken with.docs/api-reference.mdnow documents both behaviours.The related
IsRestorableboundary-range check from the issue was already added in #97.One behaviour change: the service now rejects a boundary it doesn't know about, including one built with
new SaveBoundary(...). Before, it would undo to whatever position that boundary named. The existing test that passes a hand-built boundary already expectedfalsefor its own reason, so it still passes.Tests
UndoToSaveBoundary_BoundaryHeldAcrossTrim_UndoesToSavedStateis the issue's repro. It expects value 1, position -1 and no unsaved changes.UndoToSaveBoundary_BoundaryRemovedByBranching_ReturnsFalsechecks that nothing is undone andGetCommandsToUndois empty.🤖 Generated with Claude Code
https://claude.ai/code/session_01TX4nouJvSXNs7eSvDP13qU
Generated by Claude Code