fix: correct presence-cursor mapping for nested containers, hard breaks, and remote edits - #80
Open
kongsgard wants to merge 1 commit into
Open
Conversation
…ks, and remote edits Four fixes to selection/cursor handling, each independent: 1. cursorToAbsolutePosition: stop the parent-walk instead of throwing "Unreachable code" when the editor is bound to a nested container (containerId) rather than the doc root. The walk climbed past the bound node into the surrounding document and threw. 2. absolutePositionToCursor: walk across multiple LoroText leaves in one block (e.g. text split by a hard break) instead of always binding to the first leaf with a possibly out-of-range offset. 3. Cursor widget decorations get a stable per-peer key so ProseMirror reuses the DOM across redraws instead of recreating it (caret flashing). 4. updateNodeOnLoroEvent: restore the local selection in the same transaction as the content replacement (bounds-checked) instead of a deferred setTimeout, so the caret does not jump to the doc boundary when a remote peer edits elsewhere. Selection is also captured before clearChangedNodes mutates the mapping it depends on. Adds tests/cursor.test.ts covering fixes 1 and 2.
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.
Disclaimer: This PR was written with the help of AI. I'm not that familiar with the details of this repository yet, but the changes seem to solve the issues mentioned below.
Four fixes to selection/cursor handling, each independent:
cursorToAbsolutePosition: stop the parent-walk instead of throwing "Unreachable code" when the editor is bound to a nested container (containerId) rather than the doc root. The walk climbed past the bound node into the surrounding document and threw.
absolutePositionToCursor: walk across multiple LoroText leaves in one block (e.g. text split by a hard break) instead of always binding to the first leaf with a possibly out-of-range offset.
Cursor widget decorations get a stable per-peer key so ProseMirror reuses the DOM across redraws instead of recreating it (caret flashing).
updateNodeOnLoroEvent: restore the local selection in the same transaction as the content replacement (bounds-checked) instead of a deferred setTimeout, so the caret does not jump to the doc boundary when a remote peer edits elsewhere. Selection is also captured before clearChangedNodes mutates the mapping it depends on.
Adds tests/cursor.test.ts covering fixes 1 and 2.