Skip to content

fix(editor): preserve paragraph styles when splitting with Enter - #3705

Merged
vcapretz merged 7 commits into
canaryfrom
fix/editor-preserve-paragraph-styles-on-split
Aug 10, 2026
Merged

fix(editor): preserve paragraph styles when splitting with Enter#3705
vcapretz merged 7 commits into
canaryfrom
fix/editor-preserve-paragraph-styles-on-split

Conversation

@vcapretz

@vcapretz vcapretz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Pressing Enter in the middle of a paragraph with custom styles (e.g. a font size set via the inspector) split the paragraph but stripped the styles from the second half. Text color survived because it lives as a mark on the text nodes, while font size lives on the paragraph's style attribute.

The split itself was never the problem: TipTap attributes default to keepOnSplit: true, so the style attribute was correctly copied to the new paragraph. The bug was an Enter keyboard shortcut in the StyleAttribute extension that ran resetAttributes('paragraph', 'style') in a requestAnimationFrame callback right after the split — wiping the styles off the paragraph the cursor landed in. ClassAttribute had the identical reset for class.

Those shortcuts exist for a reason, though: without them, pressing Enter at the end of a styled paragraph would produce an empty paragraph that inherits the custom style/class, and everything typed next would continue in it. So instead of removing them, this PR makes the reset conditional:

  • Keep the Enter shortcuts in StyleAttribute and ClassAttribute, but skip the reset when the selection end is not at the end of its block — i.e. when Enter actually splits text and the content moved into the new paragraph must keep its style/class
  • Still reset when Enter creates a fresh empty paragraph (cursor at the end of the block), preserving the original "new paragraph starts with default styles" behavior
  • This also fixes pressing Enter at the start of a styled paragraph, which previously wiped the style of the existing content
  • Regression tests cover both cases: mid-paragraph split keeps style/class on both halves, and Enter at the end still yields a default new paragraph

Test plan

  • Browser integration suite passes (9 tests), including the new mid-split and end-of-paragraph specs
  • Editor unit suite: 308 passed, 0 failed (23 spec files fail to load with a pre-existing react-email package-resolution error, reproducible on a clean canary checkout)
  • Manual check in the editor: set a custom font size on a paragraph, press Enter mid-text, confirm both paragraphs keep the size; press Enter at the end, confirm the new paragraph starts with default styles

Made with Cursor

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-email Ready Ready Preview Aug 10, 2026 3:59pm
react-email-demo Ready Ready Preview Aug 10, 2026 3:59pm

@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c5deffc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@react-email/editor Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gabrielmfern

Copy link
Copy Markdown
Member

@cursor can you add a changeset to this pull request? it should be one short sentence

@cursor

cursor Bot commented Aug 10, 2026

Copy link
Copy Markdown

Done — I added a changeset to the PR. The new file .changeset/tidy-parks-look.md declares a patch bump for @react-email/editor with the one-line description "Preserve paragraph style and class attributes when splitting a paragraph with Enter". It's committed and pushed to the PR branch, so the changeset-bot warning should clear on the next check.

Open in Web Open in Cursor 

@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@react-email/editor@3705

commit: c5deffc

Co-authored-by: Gabriel Miranda <gabrielmfern@outlook.com>
Comment thread packages/editor/src/extensions/paragraph-split.spec.ts Outdated
…ration suite

Co-authored-by: Gabriel Miranda <gabrielmfern@outlook.com>
@gabrielmfern

Copy link
Copy Markdown
Member

@cursor lint

@cursor

cursor Bot commented Aug 10, 2026

Copy link
Copy Markdown

Fixed the lint failure. Biome's formatter was flagging a stray blank line before the closing }); in both style-attribute.tsx and class-attribute.tsx — leftovers from removing the addKeyboardShortcuts blocks. I ran Biome's auto-fix on both files, confirmed the full repo pnpm lint now exits cleanly (the one remaining warning about !important in a CSS file is pre-existing and doesn't fail the check), and pushed the fix to the PR branch, so the lint job should go green on the new commit.

Open in Web Open in Cursor 

Co-authored-by: Gabriel Miranda <gabrielmfern@outlook.com>
klotty
klotty previously approved these changes Aug 10, 2026

@klotty klotty 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.

0 issues found across 4 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Focused bug fix: removes the Enter shortcuts that reset paragraph style/class after a split, and adds a regression test showing both paragraphs retain the attributes. No public, operational, or data tradeoff remains for human review.

Re-trigger cubic

…mpty paragraphs

Instead of removing the StyleAttribute/ClassAttribute Enter shortcuts,
keep them but skip the reset when Enter splits a paragraph mid-text, so
the content moved into the new paragraph keeps its style/class. Pressing
Enter at the end of a styled paragraph still starts a fresh default
paragraph, preserving the original intent of the shortcuts.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/editor/src/extensions/class-attribute.tsx
Comment thread packages/editor/src/extensions/style-attribute.tsx
@cubic-dev-ai
cubic-dev-ai Bot dismissed klotty’s stale review August 10, 2026 15:24

Dismissed because Cubic found issues in a newer review.

@cubic-dev-ai cubic-dev-ai Bot 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.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 1 file (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread apps/web/src/app/api/check-spam/check-spam.spec.tsx
@vcapretz
vcapretz merged commit b039b36 into canary Aug 10, 2026
20 checks passed
@vcapretz
vcapretz deleted the fix/editor-preserve-paragraph-styles-on-split branch August 10, 2026 16:01
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.

5 participants