Skip to content

fix: correct presence-cursor mapping for nested containers, hard breaks, and remote edits - #80

Open
kongsgard wants to merge 1 commit into
loro-dev:mainfrom
kongsgard:fix/nested-container-and-presence-cursors
Open

fix: correct presence-cursor mapping for nested containers, hard breaks, and remote edits#80
kongsgard wants to merge 1 commit into
loro-dev:mainfrom
kongsgard:fix/nested-container-and-presence-cursors

Conversation

@kongsgard

Copy link
Copy Markdown

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:

  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.

…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.
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.

1 participant