Skip to content

Make a table survive its own source - #161

Open
luca-chen198 wants to merge 2 commits into
mainfrom
fix/table-invisible-and-cell-newline
Open

Make a table survive its own source#161
luca-chen198 wants to merge 2 commits into
mainfrom
fix/table-invisible-and-cell-newline

Conversation

@luca-chen198

Copy link
Copy Markdown
Member

One real note surfaced three defects in the same subsystem: it rendered as a completely blank page.

The blank page

The note's only content was a 14-line table, so the whole document collapsed into one hidden source run. A collapsed block hides its raw text by shrinking it to a near-zero font and kerning the rest of its width away — but .kern applies to every character in its range, so a run of n characters ends up width + n * kern wide. Feeding it the run's FULL width overshot by (n − 1) widths.

AppKit clamps most such lines to zero width, which is why this never showed. One line in that note held — a z plus U+0304 — and that line did not clamp: it laid out at x = +1783 with width −1783, dragging usageBoundsForTextContainer to −1778…695 on a 700pt container.

Measured, one variable at a time:

document usage bounds
the note (-1778.2, 0, 2473.2, 655.5)
same note, combining mark removed (5.0, 0, 690.0, 655.5)
same note, after this fix (5.0, 0, 690.0, 673.5)

Two more the same note found

\| truncated its row. GFM escapes the delimiter, and the escape beats every inline context because rows are split before inline parsing runs — so `Var[x(1) \| z(1:3)]` is one cell. Splitting on the raw character cut the row short at the header's column count and silently dropped the rest of the line.

<br> had no meaning. It is the only in-cell line break the format has (a row is one source line), and it drew literally. Return inside a row could therefore only tear the table in half.

Return in a table

Return — and ⇧↵, which AppKit sends as the same insertNewline: — now inserts <br> instead of splitting the row. The table's outer edges deliberately stay a plain newline: that is the only way out of a table sitting at the end of a document.

Tests

7 new tests across TableHiddenSourceGeometryTests and TableCellSourceTests; each was confirmed red against the unfixed sources. Full suite: 454 passing.

🤖 Generated with Claude Code

luca-chen198 and others added 2 commits August 18, 2026 11:12
`.kern` applies to EVERY character in its range, so a run of n characters
ends up `width + n * kern` wide. Hiding a run with the run's FULL width
therefore overshot by (n - 1) widths. AppKit clamps most such lines to
zero, which is why it never showed — until a line held a composed
character sequence (`z` + U+0304), which instead laid out at x = +1783
with width -1783 and dragged the container's usage bounds to -1778…695
on a 700pt view. A note whose only content was such a table rendered
blank.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two things a GFM row is allowed to hold that we dropped:

`\|` escapes the delimiter, and the escape beats every inline context
because rows are split before inline parsing runs. Splitting on the raw
character cut such a row short at the header's column count, silently
losing the rest of the line.

`<br>` is the only in-cell line break the format has, since a row IS one
source line. It drew literally, and Return inside a row could only tear
the table in half — so Return (and ⇧↵, which AppKit sends as the same
`insertNewline:`) now inserts `<br>` instead. The table's outer edges
stay a plain newline: that is the only way out of a table sitting at the
end of a document.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.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.

1 participant