Skip to content

fix: Preserve whitespace between sibling elements#5718

Merged
kof merged 5 commits into
mainfrom
fix-space-instances
Apr 25, 2026
Merged

fix: Preserve whitespace between sibling elements#5718
kof merged 5 commits into
mainfrom
fix-space-instances

Conversation

@kof
Copy link
Copy Markdown
Member

@kof kof commented Apr 23, 2026

Treat whitespace-only text nodes between element siblings as part of the previous element instead of creating a separate text node. generateFragmentFromHtml now detects when a text node consisting only of space appears between two elements and appends that space to the previous instance's last text child (if present), avoiding creation of a standalone text child. Added a regression test in plugin-html.test.tsx to verify pasted HTML like <span>✓</span> <span>text</span> preserves the space and results in two span instances (no separate text node), ensuring text-content control remains correct in the settings panel.

Treat whitespace-only text nodes between element siblings as part of the previous element instead of creating a separate text node. generateFragmentFromHtml now detects when a text node consisting only of space appears between two elements and appends that space to the previous instance's last text child (if present), avoiding creation of a standalone text child. Added a regression test in plugin-html.test.tsx to verify pasted HTML like `<span>✓</span> <span>text</span>` preserves the space and results in two span instances (no separate text node), ensuring text-content control remains correct in the settings panel.
@kof kof changed the title Preserve whitespace between sibling elements fix: Preserve whitespace between sibling elements Apr 23, 2026
kof added 4 commits April 25, 2026 17:30
…gs logic

- Restore boundary whitespace skipping (index === 0 or last) that was removed
- Gate the space-attach-to-prev logic to rich-text contexts only (hasNonRichTextContent check) so select/table/etc. are unaffected
- Track spaceAttachedToPrev flag so the next sibling element's leading space is not double-stripped
- Fix `as any` lint errors in plugin-html.test.tsx with proper type narrowing
- Update test expectations to match new behavior (space appended to prev element's text child)"
@kof kof merged commit fc70898 into main Apr 25, 2026
20 of 22 checks passed
@kof kof deleted the fix-space-instances branch April 25, 2026 17:42
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