Skip to content

[lexical] Bug Fix: more accurate line break pasting - #6395

Merged
potatowagon merged 5 commits into
mainfrom
block-br
Jul 13, 2024
Merged

potatowagon merged 5 commits into
mainfrom
block-br

Conversation

@potatowagon

@potatowagon potatowagon commented Jul 12, 2024 •

Copy link
Copy Markdown
Contributor

Improve br pasting

  • ignore only child br in block nodes and not just <p>. fixes extra br in <li> paste
  • ignore last br in block node, since thats what html is doing (src)

Test plan

Screenshot 2024-07-12 at 3 04 21 PM

Before

Screenshot 2024-07-12 at 3 04 32 PM

After

Screenshot 2024-07-12 at 3 06 30 PM


Screenshot 2024-07-12 at 3 27 27 PM

before

Screenshot 2024-07-12 at 3 27 45 PM

after

Screenshot 2024-07-12 at 3 27 39 PM

@vercel

vercel Bot commented Jul 12, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 7:32am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 7:32am

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 12, 2024
@github-actions

github-actions Bot commented Jul 12, 2024 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
lexical - cjs 28.48 KB (0%)
lexical - esm 28.29 KB (0%)
@lexical/rich-text - cjs 36.93 KB (0%)
@lexical/rich-text - esm 28.16 KB (0%)
@lexical/plain-text - cjs 35.6 KB (0%)
@lexical/plain-text - esm 25.34 KB (0%)
@lexical/react - cjs 38.8 KB (0%)
@lexical/react - esm 29.31 KB (0%)

@potatowagon
potatowagon marked this pull request as draft July 12, 2024 07:15
@potatowagon potatowagon changed the title Block br [lexical] Bug Fix: more accurate line break pasting Jul 12, 2024
@potatowagon
potatowagon marked this pull request as ready for review July 12, 2024 07:33
@potatowagon
potatowagon added this pull request to the merge queue Jul 13, 2024
Merged via the queue into main with commit e6099f3 Jul 13, 2024
2wheeh pushed a commit to 2wheeh/lexical that referenced this pull request Jul 17, 2024
@potatowagon
potatowagon deleted the block-br branch July 26, 2024 05:51
potatowagon added a commit to potatowagon/lexical that referenced this pull request Jun 30, 2026
…naged line breaks

Follow-up to meta#8750 implementing @etrepum's approach from meta#7600.

meta#6395 dropped every trailing <br> in a block on import to match HTML's
non-rendering behavior, but that loses authored trailing breaks on
round-trip serialization. meta#8750 narrowed the drop to Safari's
Apple-interchange-newline clipboard artifact, but that gate doesn't fire
for ordinary structural/authored trailing breaks (or non-Safari pastes),
so the phantom-blank-line regression persists for those.

Instead, drop a trailing <br> only when it is a *managed* line break:
- data-lexical-managed-linebreak="true": the terminator Lexical's
  reconciler already injects via LexicalDOMSlot.setManagedLineBreak, so
  re-importing Lexical's own exported HTML stays idempotent.
- class="Apple-interchange-newline": Safari's clipboard transport artifact.

An ordinary authored trailing <br> carries neither marker and is now
preserved, so round-trip serialization to HTML is lossless while
rendering of external pasted HTML stays faithful. Browser-agnostic for
the Lexical-managed case.

Applies the same gate to both LineBreakNode.importDOM and the
@lexical/html coreImportRules LineBreakRule. Adds test coverage for the
preserved / managed / Apple-interchange cases.

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 759bc0b9 Deployed Jul 12, 2024 by vercel[bot]
Preview – lexical — 759bc0b9 Deployed Jul 12, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants