Skip to content

fix(super-editor): anchor header/footer caret to the line box after a tab - #3870

Merged
caio-pizzol merged 4 commits into
superdoc:v1from
PopaSerban:fix/header-footer-caret-tab-anchoring
Aug 10, 2026
Merged

fix(super-editor): anchor header/footer caret to the line box after a tab#3870
caio-pizzol merged 4 commits into
superdoc:v1from
PopaSerban:fix/header-footer-caret-tab-anchoring

Conversation

@PopaSerban

@PopaSerban PopaSerban commented Aug 5, 2026

Copy link
Copy Markdown

PR description:

Typing in a header or footer and pressing Tab renders the caret about 5.5px below its own line, hanging past the bottom of the row. Typing any character snaps it back, so the insertion point was always correct — only the caret's painted position between the Tab and the next keystroke was wrong.

This is the same symptom as #3507, which #3677 fixed for body text in June. That fix only touched DomSelectionGeometry.ts, so the header/footer caret path never got it.

Refs #3507, #3677

BeforeAfter
before.mov
after.mov

Review in cubic

Caret paths each decided independently whether an element's own box or its
enclosing line box is the caret box. A tab span and an empty SDT placeholder
are painted with a box that is deliberately not the line box, so reading the
element's own rect puts the caret off its row.

Move that rule into dom-observer/CaretLineAnchoring.ts and route the body
caret path through it, so a new caret path gets the rule by construction
rather than by remembering a comment.

No behavior change.
… tab

Typing in a header or footer and pressing Tab rendered the caret about 5.5px
below its own line, hanging past the bottom of the row. Typing any character
snapped it back, so the insertion point was always correct - only the caret's
painted position between the Tab and the next keystroke was wrong.

A painted tab span is deliberately height: line.lineHeight with
vertical-align: bottom (SD-3330) inside a .superdoc-line carrying
font-size: 0, so its own border box starts below the line top.
computeCaretRect resolves through #computeVisibleSurfaceCaretRect, which
falls back to the element's own rect for entries with no child text node.
A tab span is painted empty, so it took that branch and handed the tab's box
to the caret as both y and height.

Same symptom as superdoc#3507, which superdoc#3677 fixed for body text. That fix only
touched DomSelectionGeometry, so the header/footer path never got it.

Refs superdoc#3507, superdoc#3677

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Re-trigger cubic

@superdoc superdoc deleted a comment from qodo-code-review Bot Aug 10, 2026

@caio-pizzol caio-pizzol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, @PopaSerban! I reproduced the bug and confirmed this PR fixes it. The code and tests look good.

Approving - the failing CI check is unrelated.

@caio-pizzol
caio-pizzol merged commit 63c9f40 into superdoc:v1 Aug 10, 2026
52 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants