Repository navigation
Update collab text to use anchor tracking - #27907
Conversation
|
Hi! Thank you for opening this PR. Want me to review it? Based on the diff (411 lines, 7 files), I've queued these reviewers:
How this works
|
There was a problem hiding this comment.
Pull request overview
Updates the React plain-text collaboration utilities to track textarea selections via PlainText.Tree insertion anchors, so selections follow remote edits without manual per-delta cursor math.
Changes:
- Add
PlainText.Tree.createInsertionAnchor()(tree) and switch selection tracking to use anchor indices (React hook + editor view). - Extend
useTreeSynchronizedStringto exposesetSelection()and compute selections from anchors. - Simplify
applyTextOpsto only return the updated string; expand tests to cover anchor-based selection behaviors (including hydration and surrogate pairs).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/framework/react/src/text/plain/useTreeSynchronizedString.ts | Reworks selection tracking to use insertion anchors and exposes setSelection() to update tracked selection. |
| packages/framework/react/src/text/plain/plainUtils.ts | Simplifies applyTextOps to return just the updated string; keeps reread-based selection remapping helper. |
| packages/framework/react/src/text/plain/plainTextView.tsx | Wires textarea onSelect/onChange to setSelection() so the editor can preserve selection across remote edits. |
| packages/framework/react/src/test/text/useTreeSynchronizedString.spec.ts | Adds/updates tests for anchor-based selection behavior, bounds clamping, surrogate pairs, and hydration. |
| packages/framework/react/src/test/text/plainUtils.test.ts | Updates tests to match the simplified applyTextOps return type and scope. |
| packages/framework/react/api-report/react.alpha.api.md | API report update for SynchronizedString.setSelection. |
| packages/framework/fluid-framework/api-report/fluid-framework.alpha.api.md | API report update for PlainText.Tree.createInsertionAnchor. |
| packages/dds/tree/src/text/textDomainFormatted.ts | Adds createInsertionAnchor implementation for formatted text’s underlying content array. |
| packages/dds/tree/src/text/textDomain.ts | Adds createInsertionAnchor to PlainText members and implements it via array insertion anchors. |
| packages/dds/tree/src/test/text/textDomain.spec.ts | Adds hydration test verifying insertion anchors track across edits. |
| packages/dds/tree/api-report/tree.alpha.api.md | API report update for PlainText.Tree.createInsertionAnchor. |
| .changeset/small-suns-tickle.md | Declares minor bumps and documents the new anchor-based selection tracking behavior. |
Suppressed comments (2)
packages/framework/react/src/text/plain/plainTextView.tsx:108
HTMLTextAreaElement.selectionStart/selectionEndare typed asnumber | null. Normalize them (e.g.?? 0) before callingsetSelectionto avoid null propagation / TS errors.
(event: SyntheticEvent<HTMLTextAreaElement>) => {
setSelection({
start: event.currentTarget.selectionStart,
end: event.currentTarget.selectionEnd,
});
packages/framework/react/src/text/plain/useTreeSynchronizedString.ts:78
- The example uses
selectionStart/selectionEnddirectly, but in TS DOM typings these arenumber | null. Adding a fallback avoids TS errors when consumers copy/paste this snippet.
* onChange={(e) => {
* TreeAlpha.context(tree).runTransaction(() => syncTextToTree(tree, e.target.value));
* setSelection({ start: e.target.selectionStart, end: e.target.selectionEnd });
* }}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Joshua Smithrud (Josmithr)
left a comment
There was a problem hiding this comment.
Added a couple more comments, but otherwise this is looking good to me.
|
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output |
Bundle size comparisonBase commit: Pending — |
Description
Updates collab text plain text selection tracking to use the array node anchor tracking feature.