fix: restore selection when undoing the last history item - #1102
Open
fendermoon wants to merge 1 commit into
Open
fendermoon wants to merge 1 commit into
fendermoon wants to merge 1 commit into
Conversation
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.
Summary
Fixes #1100.
Stack::pop()decreases the logical item count but keeps the row containing itsremote delta alive for cursor restoration. When the popped item was the last
one,
transform_based_on_this_delta()returned early becauseself.is_empty()checks that logical count. The subsequent cursor transform therefore used the
remote delta without rebasing it through the undo.
Check
self.stack.is_empty()instead. This keeps the empty-storage guard whileallowing the retained row's delta to be transformed. It does not introduce a new
history or change the merge algorithm.
The regression starts with
Hello world!, commits it, and then creates theUndoManager. It deletes the selected
ello, imports a peer'sHiandiiinsertions, and undoes the deletion. The text must be
Hi Helloii world!andthe absolute selection positions delivered in
on_popmetadata(
CursorWithPos.pos.pos) must be[4,8], not[4,10]. Resolving the retainedcursors through
doc.get_cursor_pos(...).current.posalready returns[4,8]before the fix; the regression distinguishes these two results.
The same test first runs a control with one unrelated map edit in the history.
The control passes without the fix; the last-item arm fails. Neither arm loads
a snapshot or calls
clear()before editing. Both also check fresh snapshotand peer readback of the document value and version vector.
Validation
Base:
d9ddfba195f9363653ac1d83e744641dcb337f4e.Prepared commit:
7db750e38d61fb83200d9f9665931e77bce5fad7.older_item=falseat theon_popmetadata assertion, actual
[4,10], expected[4,8]. The older-item control,text/readback checks and cursor-resolution assertion pass first.
cargo test --locked -p loro -p loro-internal --lib --tests -- --test-threads=1passes 1,050 tests; 12 existing tests are ignored. Native macOS, Rust 1.94.0,
dev debug information disabled and incremental compilation disabled.
Includes the repository-required patch changeset. No public API or storage
format changes are proposed.