Skip to content

SD-2570 - fix: document API tracked changes not fully rendered on document#2825

Merged
caio-pizzol merged 14 commits into
mainfrom
gabriel/sd-2570-bug-missing-content-inserted-by-ai-simplified-fix
Apr 24, 2026
Merged

SD-2570 - fix: document API tracked changes not fully rendered on document#2825
caio-pizzol merged 14 commits into
mainfrom
gabriel/sd-2570-bug-missing-content-inserted-by-ai-simplified-fix

Conversation

@chittolinag
Copy link
Copy Markdown
Contributor

@chittolinag chittolinag commented Apr 15, 2026

Issue

Tracked text inserted programmatically with editor.doc.insert(..., { changeMode: 'tracked' }) was truncated in the document view when the inserted string contained newline characters (\n). Only the content before the first newline was rendered, even though the full text was preserved in comment bubbles and export.

Proposed solution

Align renderer run slicing with measurer behavior for inline newlines. The renderer now expands text runs containing \n into text/break/text segments before slicing line ranges, so measured line indices map correctly and all multiline tracked content renders in the document.

@linear
Copy link
Copy Markdown

linear Bot commented Apr 15, 2026

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9781989a3e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/layout-engine/painters/dom/src/renderer.ts Outdated
Comment thread packages/layout-engine/painters/dom/src/renderer.ts Outdated
Copy link
Copy Markdown
Contributor

@artem-harbour artem-harbour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chittolinag ran this in the dev app console:

await ed.doc.insert(
  { value: 'first line here\nsecond line here\nthird line here' },
  { changeMode: 'tracked' }
);

text shows up, but lines 2 and 3 have no data-pm-start / data-pm-end and clicking them doesn't move the caret. sliceRunsForLine got the fix, but computeLinePmRange (contracts/src/pm-range.ts:82) and the second copy in layout-bridge/src/text-measurement.ts:315 still read un-split runs.

  • restore ParagraphMeasure.expandedRuns from #2824 — one source of truth for all three read-sites.
  • rebase: f778c4a65 added tab handling in the measurer that the helper doesn't mirror.

Comment thread packages/layout-engine/painters/dom/src/renderer.ts Outdated
Comment thread packages/layout-engine/painters/dom/src/renderer.ts Outdated
Comment thread packages/layout-engine/painters/dom/src/renderer.ts Outdated
Comment thread packages/layout-engine/painters/dom/src/index.test.ts Outdated
Comment thread packages/layout-engine/painters/dom/src/index.test.ts Outdated
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@chittolinag
Copy link
Copy Markdown
Contributor Author

@chittolinag ran this in the dev app console:

await ed.doc.insert(
  { value: 'first line here\nsecond line here\nthird line here' },
  { changeMode: 'tracked' }
);

text shows up, but lines 2 and 3 have no data-pm-start / data-pm-end and clicking them doesn't move the caret. sliceRunsForLine got the fix, but computeLinePmRange (contracts/src/pm-range.ts:82) and the second copy in layout-bridge/src/text-measurement.ts:315 still read un-split runs.

You're right about data-pm-start, data-pm-end and computeLinePmRange. Just fixed them. Thanks for pointing them out!

I did notice a caret issue around tracked changes (might have been what you experienced). If you open a document with tracked changes and click directly on a tracked change once it's loaded, using the arrow keys won't work because the editor is not focused. So if you use up/down for example, the page will scroll up an down instead of navigating within the document (and left/right won't have any effect). This also happens with a blank document. If you open a blank document (and do not type anything, do not focus the editor) and programatically insert a tracked change, if you click it, the same behavior will happen. I am not sure if this is the issue that you faced, but that is already happening on main, so not introduced here. I think it makes more sense to create a separate ticket to handle that. What do you think?

@chittolinag chittolinag requested a review from caio-pizzol April 22, 2026 19:10
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @chittolinag! thanks for last round, position fixes look clean. on the caret focus thing, repro'd here too - split it off, sgtm.

one regression this PR adds: tracked text with newlines leaves empty lines visible in original mode (and same in final for deletes). fix is small, left it inline with repro steps.

needs work.

Comment thread packages/layout-engine/pm-adapter/src/converters/paragraph.ts Outdated
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @chittolinag! thanks for addressing last round.

not there yet - text with both tabs and newlines renders wrong and loses content. three inline.

Comment thread packages/layout-engine/pm-adapter/src/converters/paragraph.ts
Comment thread packages/layout-engine/painters/dom/src/renderer.ts
Comment thread packages/layout-engine/pm-adapter/src/converters/paragraph.ts Outdated
@caio-pizzol caio-pizzol force-pushed the gabriel/sd-2570-bug-missing-content-inserted-by-ai-simplified-fix branch from 6da509e to 984575a Compare April 23, 2026 23:36
chittolina and others added 3 commits April 24, 2026 09:57
…lineNewlines

The previous guard early-returned the whole iteration when a segment was
empty, which also skipped the break emit and cursor advance. Leading
\n, trailing \n, and consecutive \n\n inputs would drop breaks and
shift pm positions downstream.

Guard only the empty-text push so the break logic still runs for every
\n in the source text.
Copy link
Copy Markdown
Contributor

@caiopizzol caiopizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @chittolinag! thanks for addressing last round.

on the \t+\n you were right - doc.insert doesn't hit it (only a raw schema.text() transaction does), so it's latent drift, worth a follow-up but not a blocker.

i rebased on latest main and pushed c861628 tightening the empty-segment guard (leading and consecutive \n were dropping breaks) with tests for the edge cases.

lgtm.

@caio-pizzol caio-pizzol enabled auto-merge (squash) April 24, 2026 14:28
@caio-pizzol caio-pizzol self-requested a review April 24, 2026 14:28
@caio-pizzol caio-pizzol merged commit 7c9774c into main Apr 24, 2026
63 checks passed
@caio-pizzol caio-pizzol deleted the gabriel/sd-2570-bug-missing-content-inserted-by-ai-simplified-fix branch April 24, 2026 14:35
@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 24, 2026

🎉 This PR is included in superdoc v1.28.0-next.16

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 24, 2026

🎉 This PR is included in superdoc-cli v0.8.0-next.16

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 24, 2026

🎉 This PR is included in superdoc-sdk v1.6.0-next.52

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 24, 2026

🎉 This PR is included in superdoc v1.29.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 25, 2026

🎉 This PR is included in @superdoc-dev/mcp v0.3.0-next.1

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 25, 2026

🎉 This PR is included in superdoc-sdk v1.8.0-next.1

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 29, 2026

🎉 This PR is included in @superdoc-dev/react v1.2.0-next.49

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 29, 2026

🎉 This PR is included in vscode-ext v2.3.0-next.51

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 29, 2026

🎉 This PR is included in esign v2.6.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 29, 2026

🎉 This PR is included in template-builder v1.7.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in superdoc-cli v0.8.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in superdoc-sdk v1.8.0

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in @superdoc-dev/mcp v0.3.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in vscode-ext v2.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants