fix(document-api): align position readback with write-side offset model (SD-3109)#3243
Merged
caio-pizzol merged 1 commit intoMay 12, 2026
Conversation
β¦el (SD-3109) The Document API write side accepts text offsets in a flattened model: text contributes its length, leaf atoms contribute 1, inline wrappers (run, etc.) contribute 0. Position readback was using raw PM arithmetic (`pos - resolved.start(depth)`), which counts the wrapper boundary tokens the flattened model skips. Result: `editor.doc.bookmarks.list()` returned offsets that drifted by the number of inline wrappers in the targeted block. - Route both readback helpers through `pmPositionToTextOffset` so read and write share one offset model. - Same fix applied in `permission-ranges-adapter.ts`, which carried a parallel copy of the buggy helper. - Regression test for the round-trip invariant (write at offset N, list returns offset N). - Includes regression coverage for SD-3108 (content-control wrap by text offset). That bug did not reproduce on main; the tests stay as guardrails.
Codecov Reportβ All modified and coverable lines are covered by tests. π’ Thoughts on this report? Let us know! |
Contributor
|
π This PR is included in @superdoc-dev/react v1.2.0-next.118 The release is available on GitHub release |
Contributor
|
π This PR is included in vscode-ext v2.3.0-next.120 |
Contributor
|
π This PR is included in @superdoc-dev/mcp v0.3.0-next.75 The release is available on GitHub release |
Contributor
|
π This PR is included in superdoc v1.30.0-next.74 The release is available on GitHub release |
Contributor
|
π This PR is included in superdoc-sdk v1.8.0-next.74 |
Contributor
|
π This PR is included in superdoc-cli v0.8.0-next.92 The release is available on GitHub 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.
Position readback (
bookmarks.list, and a sibling helper in the permission-ranges adapter) was using raw PM arithmetic βpos - resolved.start(depth)β which counts the inline wrapper boundary tokens (run, etc.) that the write side's flattened text-offset model intentionally skips. So a bookmark inserted at flattened offset 19 read back at offset 22 in a doc withrun-wrapped text. Fix routes the read path throughpmPositionToTextOffsetso write and read share one offset model.permission-ranges-adapter.tsis a separate cleanup target β sharing one implementation between the two adapters would obsolete the cross-reference comment naturally. Leaving that for a later pass to keep this PR scoped to the readback fix.Review: confirm the AIDEV-NOTE wording is the right anchor β it has to survive future "simplify" passes that might revert to the naive arithmetic.