Skip to content

fix: match inline suggestion font to caret element in contenteditable editors#345

Merged
bartekplus merged 3 commits intomasterfrom
fix/inline-suggestion-font-matching-tinymce
Mar 23, 2026
Merged

fix: match inline suggestion font to caret element in contenteditable editors#345
bartekplus merged 3 commits intomasterfrom
fix/inline-suggestion-font-matching-tinymce

Conversation

@bartekplus
Copy link
Copy Markdown
Owner

Summary

  • Inline suggestion ghost now reads computed font styles from the element at the caret position (e.g. <h1>, <p>, <span>) instead of the outer contenteditable container (e.g. <body>)
  • Uses caretRect.height as the ghost's lineHeight/height to prevent baseline misalignment caused by CSS leading
  • Adds resolveCaretElement() helper that uses the Selection API to find the correct style source

Test plan

  • Added 4 unit tests covering: caret element font resolution, fallback to container, lineHeight override from caretRect, non-contenteditable passthrough
  • Manual test on TinyMCE full-featured demo: inline suggestion matches H1/H2/P fonts and aligns correctly
  • Verify no regression on regular <input> / <textarea> fields

🤖 Generated with Claude Code

bartekplus and others added 3 commits March 23, 2026 21:05
… editors

On TinyMCE and similar contenteditable editors, the inline suggestion
ghost was reading computed styles from the outer container (e.g. <body>)
instead of the element at the caret (e.g. <h1>, <p>). This caused wrong
font family, size, and weight. Additionally, the ghost used the element's
computed lineHeight which includes leading, shifting the suggestion text
below the actual baseline.

- Add resolveCaretElement() to find the DOM element at the caret position
  via the Selection API and copy its computed font styles
- Use caretRect.height as the ghost lineHeight/height instead of the
  computed lineHeight to align the text baseline with the caret

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…undary selections

P1: Replace height/overflow clamp with a top-offset approach. The ghost
now keeps the element's computed lineHeight and shifts top upward by half
the leading (lineHeight - caretHeight) / 2, so multi-line suggestions
that wrap via pre-wrap + maxWidth are no longer truncated after the first
line.

P2: Handle wrapper-boundary selections (Lexical/Reddit pattern) where
the caret is at (wrapperDiv, offset).  resolveCaretElement now descends
into the block child at the anchor offset instead of returning the
wrapper, matching ContentEditableAdapter.findInnermostBlockContainingRange
behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bartekplus bartekplus merged commit 59ba5ee into master Mar 23, 2026
8 checks passed
@bartekplus bartekplus deleted the fix/inline-suggestion-font-matching-tinymce branch March 23, 2026 20:19
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