platform: fix annotation-agnostic selection paths for base USJ#463
Open
jolierabideau wants to merge 5 commits intomainfrom
Open
platform: fix annotation-agnostic selection paths for base USJ#463jolierabideau wants to merge 5 commits intomainfrom
jolierabideau wants to merge 5 commits intomainfrom
Conversation
- Emit jsonPath/offset from base-USJ content runs in selection.utils - Update selection tests; add multi-annotation paragraph case - Platform demo: selection ref, Insert at selection, fix callback types Made-with: Cursor
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders Open Preview |
…ion-agnostic paths Update data-driven selection tests to expect base-USJ locations from $getUsjSelectionFromEditor when paranext document paths differ, including a marker-mode special case for one content[6] text location. Made-with: Cursor
…iven test Made-with: Cursor
Extend $textRequiresStandardLexicalContentPath to treat VerseNode and MilestoneNode like CharNode so collapsed base-USJ paths are not emitted for text that follows those nodes. That keeps jsonPath aligned with $getContentChildAtIndex and round-trips through $getNodeFromLocation. Update unit tests for editable para with verse and editable milestone cases. Made-with: Cursor
…arkNode now adds text lengths of preceding siblings within a TypedMarkNode before applying the local TextNode offset, fixing USJ round-trip when formatting splits produce multiple TextNodes under one mark. Also: resolve shared-react lint (data-driven selection tests use describe.each and it.each; index-signature style; filter console warn eslint); add round-trip test for cursor in second TextNode inside a mark. Made-with: Cursor
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.
Fix annotation-agnostic USJ selection paths (
onSelectionChange/setAnnotation)Problem
Editorial’sonSelectionChange(andEditorRef.getSelection()) buildSelectionRangefrom Lexical via$getUsjSelectionFromEditor→$getLocationFromNode. For plain text, paths used**$getJsonPathIndexes**, which treats each**TypedMarkNode**(annotation wrapper) as its own content sibling—matching the Lexical tree, not canonical USJ.So after one annotation (e.g.
"neva"), selecting following text (e.g."sleep") could report paths like$.content[…].content[2]with a small offset. Host code and JSONPath helpers resolve locations against actual USJ (no extra per-annotationcontententries), so queries like$.content[20].content[2]fail with “No result found for JSONPath query”. Different annotation providers cannot reason about each other’s marks if coordinates are tied to the annotated Lexical shape.Expected:
jsonPath+offsetidentify the same scripture position as in base USJ, independent of existing annotations.Solution
For text nodes and text inside
TypedMarkNode,$getLocationFromNodenow emits:**jsonPath**from**$getJsonPathIndexesForBaseUsj**: collapses adjacentTextNode+TypedMarkNodeinto one “content run” and shares one base-USJ content index (indices advance only on non-run nodes such as markers / verses).**offset**from**$getOffsetInContentRun**: character offset within that run (sum of preceding plain text and marked text in the paragraph).Reverse resolution (
$getRangeFromUsjSelection/$getNodeFromLocation) already navigates base-USJ paths and unwrapsTypedMarkNodewhen needed, so forward and backward paths stay aligned.Changes
libs/shared-react/.../selection.utils.ts$getJsonPathIndexesForBaseUsj,$getContentIndexWithinParentForBaseUsj,$getOffsetInContentRun.selection.utils.test.tscontent[0], offsets 12–17).demos/platform/.../app.tsxSelectionRangein a ref; Insert at selection usessetAnnotationwith current selection; replace deprecatedMarginalProps<Console>typing withSelectionRange+ localOnUsjChangeWithComments.How to verify
nx test shared-react(or targetedselection.utils.test.ts).content[n]on USJ JSONPath resolution.Scope / follow-ups
Made-with: Cursor
This change is