Skip to content

Fix lineCount inconsistency between layout() and layoutWithLines()#20

Open
yuribodo wants to merge 1 commit into
chenglou:mainfrom
yuribodo:fix/line-count-trailing-spaces
Open

Fix lineCount inconsistency between layout() and layoutWithLines()#20
yuribodo wants to merge 1 commit into
chenglou:mainfrom
yuribodo:fix/line-count-trailing-spaces

Conversation

@yuribodo
Copy link
Copy Markdown

Summary

  • walkPreparedLinesSimple was missing the isSimpleCollapsibleSpace guard that countPreparedLinesSimple already has
  • When a trailing collapsible space overflowed the line edge, the walk path treated it as a line break (via canBreakAfter) instead of letting it hang past the edge per CSS white-space: normal semantics
  • This caused layoutWithLines() to report a higher lineCount than layout() for inputs where content after the hanging space would still fit on the same line
  • Added a regression test with synthetic segments that reproduces the exact divergence

Fixes #11

Test plan

  • bun run check passes (tsc + oxlint)
  • bun test passes (61/61, was 60)
  • New test fails without the fix, passes with it
  • Existing trailing-whitespace test still passes

walkPreparedLinesSimple was missing the isSimpleCollapsibleSpace guard
that countPreparedLinesSimple has. When a trailing collapsible space
overflowed the line edge, the walk path treated it as a line break via
canBreakAfter instead of letting it hang past the edge per CSS
white-space: normal semantics. This caused layoutWithLines() to report
a higher lineCount than layout() for inputs where content after the
hanging space would still fit on the same line.

Fixes chenglou#11
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.

layout() and layoutWithLines() return different lineCount for trailing collapsible spaces

1 participant