Skip to content

fix: preserve streamed line starts inside a chunk#129

Draft
lttlin wants to merge 1 commit intochenglou:mainfrom
lttlin:fix/pretext/121-streaming-line-start
Draft

fix: preserve streamed line starts inside a chunk#129
lttlin wants to merge 1 commit intochenglou:mainfrom
lttlin:fix/pretext/121-streaming-line-start

Conversation

@lttlin
Copy link
Copy Markdown

@lttlin lttlin commented Apr 13, 2026

Problem

layoutNextLine() and layoutNextLineRange() renormalize every continuation cursor as if it were starting from a fresh paragraph or chunk boundary. In mixed-script edge cases with a ZWSP break opportunity followed by collapsible whitespace, that can skip a real continuation segment and merge two streamed lines that layoutWithLines() keeps separate.

Root Cause

The line-start normalization helpers unconditionally skipped space, zero-width-break, and soft-hyphen segments even when the caller was resuming from an exact end cursor returned by the previous streamed line. That normalization is correct at the true start of a paragraph or chunk, but it is too aggressive for continuation cursors inside an existing chunk.

Fix

Only trim collapsible leading break-opportunity segments when the cursor is at the true paragraph start or chunk start. If the caller resumes from a later in-chunk cursor, preserve it exactly and continue streaming from that segment.

Validation

  • cd /tmp/pretext_issue_121 && ~/.bun/bin/bun test src/layout.test.ts --test-name-pattern 'streaming canary preserves exact continuation cursors after a ZWSP break opportunity|layoutWithLines strips leading collapsible space after a ZWSP break the same way as layoutNextLine|layoutNextLine reproduces layoutWithLines exactly'
  • cd /tmp/pretext_issue_121 && ~/.bun/bin/bun test src/layout.test.ts

Closes #121

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.

Bug: layoutNextLine and walkLineRanges mismatch with layoutWithLines

1 participant