Index a subtree that joins or leaves a tree the session owns - #18
Merged
Conversation
mutateSubtree covers an edit INSIDE a subtree that is attached on both sides of the change. A host that edits nodes directly also adds and removes WHOLE entries — a paste, a delete, and each one's undo — and that shape has no before/after pair to diff: the nodes either did not exist yet, or are about to stop existing. So: indexSubtree(root) after attaching, unindexSubtree(root, detach) before removing. The second takes the detach as a callback because an id is a PATH, which makes the ordering part of the contract instead of a comment: the ids have to be read while the subtree is still attached, or the index goes on handing out an entry that has left the tree and the next edit routed at that row mutates an orphan. It releases the selection over the whole subtree for the same reason mutateSubtree releases it over the nodes an edit dropped. Tests cover both directions, the ordering, a subtree with children, and the selection release.
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.
A node id is a live getter over the node's path, so a subtree that is attached or detached silently rekeys every node inside it.
mutateSubtreealready repaired the index for an in-place edit; these two helpers cover the other two cases.indexSubtree(root)— after attaching a subtree, flatten it and register every id.unindexSubtree(root, detach?)— read the ids while still attached, run the detach inside atry, then delete the ids and release their selection infinally. Reading before and deleting after is the only order that works.Why now
A consumer repainting one entry of a dictionary rather than re-parsing the whole file has to keep the index honest itself: the wide re-parse used to repair it as a side effect. Without these,
findNodeByIdstops resolving the very rows the repaint just painted, and the next edit on one of them fails to locate its node.Tests
test/indexSubtree.test.ts— both directions, the read-before/delete-after ordering, a subtree with children, and the selection release. Full suite green (131 files, 4101 passed, 26 skipped);tsc --noEmitandscripts/leak-check.mjsclean.The version bump to 1.11.0 is the second commit, as usual.