Skip to content

fix: preserve streamed line starts inside a chunk#129

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

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
Contributor

@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

@chenglou
Copy link
Copy Markdown
Owner

Thanks! I've implement this and credited you as co-author

@chenglou chenglou closed this Apr 17, 2026
chenglou added a commit that referenced this pull request Apr 18, 2026
Normalize chunked batch line starts through the same segment-kind policy used by streaming so layoutWithLines(), walkLineRanges(), layoutNextLine(), and layout() stay aligned after zero-width break opportunities and collapsible spaces.

Classify Hangul Compatibility Jamo (U+3130..U+318F) as CJK so common Korean compatibility jamo runs break like browser text.

Refs #129, #135, #141.
Closes #121
Closes #142

Co-authored-by: mayrang <pkss0626@naver.com>
Co-authored-by: voidborne-d <voidborne-d@users.noreply.github.com>
Co-authored-by: lttlin <lttlin@gmail.com>
nice-hang pushed a commit to nice-hang/pretext that referenced this pull request Apr 18, 2026
Normalize chunked batch line starts through the same segment-kind policy used by streaming so layoutWithLines(), walkLineRanges(), layoutNextLine(), and layout() stay aligned after zero-width break opportunities and collapsible spaces.

Classify Hangul Compatibility Jamo (U+3130..U+318F) as CJK so common Korean compatibility jamo runs break like browser text.

Refs chenglou#129, chenglou#135, chenglou#141.
Closes chenglou#121
Closes chenglou#142

Co-authored-by: mayrang <pkss0626@naver.com>
Co-authored-by: voidborne-d <voidborne-d@users.noreply.github.com>
Co-authored-by: lttlin <lttlin@gmail.com>
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

2 participants