Skip to content

Merge blank lines upward instead of into the table - #59

Merged
ptheofan merged 2 commits into
mainfrom
58-blank-before-table
Aug 22, 2026
Merged

Merge blank lines upward instead of into the table#59
ptheofan merged 2 commits into
mainfrom
58-blank-before-table

Conversation

@ptheofan

Copy link
Copy Markdown
Owner

removeLeadingBlankParagraph deleted [tableStart - 1, tableStart)
exactly the range the API rejects:

Deleting the newline character before a Table, TableOfContents or
SectionBreak without deleting the element.
DeleteContentRangeRequest

The call sat in a try/catch that logged and moved on, so every attempt
failed quietly and the blank stayed. suppressLeadingBlank has never
suppressed anything.

Fix. Delete the newline of the paragraph above the blank instead.
The blank merges into it, the surviving paragraph keeps that paragraph's
text and style, and the newline in front of the table is never touched.

Targeted at what the document should hold anyway — one blank after body
text, which separates the two, none after a heading, which already
carries space below it. Doubles collapse, and a rewrite leaves no gap
where content used to be. It now runs on the push path as well, which is
where a wholesale rewrite strands them.

Verification

Four tests, mutation-checked against the old range: restoring
[tableStart-1, tableStart) fails three of them, including
never deletes the newline that belongs to the table. They assert the
ranges that actually reach batchUpdate.

pnpm test 1039 passed / 63 files · typecheck clean · lint clean.

Closes #58

🤖 Generated with Claude Code

ptheofan and others added 2 commits August 22, 2026 17:52
removeLeadingBlankParagraph deleted [tableStart-1, tableStart) -- exactly
the newline Google refuses to delete unless the table goes with it. The
call sat in a try/catch, so every attempt failed quietly and the blank
stayed: suppressLeadingBlank has never actually suppressed anything.

Deleting the newline of the paragraph *above* the blank merges the blank
into it instead. The surviving paragraph keeps that paragraph's text and
style, and the newline in front of the table is never touched.

Applied to what the document should hold anyway -- one blank after body
text, none after a heading -- so doubles collapse and a rewrite leaves no
gap where content used to be. It now runs on the push path too, which is
where a wholesale rewrite strands them.

Closes #58

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Merging a blank upward reached for `above.endIndex - 1` even when the
element above was a table, whose end Google refuses to delete without the
whole element. Against a real document that failed the request outright:

  Invalid requests[0].deleteContentRange {984,985}

A blank between two tables has nothing above it whose newline may be
taken, so it stays -- deleting its own newline is exactly what the API
rejects. The comment already said as much; the code did not.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ptheofan
ptheofan merged commit 30ba8bc into main Aug 22, 2026
5 checks passed
@ptheofan
ptheofan deleted the 58-blank-before-table branch August 22, 2026 17:41
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.

Blank lines before tables cannot be removed the way the code tries to

1 participant