Skip to content

[lexical] Bug Fix: Preserve pasted blocks after consecutive line breaks - #8890

Open
wanxiankai wants to merge 1 commit into
facebook:mainfrom
wanxiankai:fix/preserve-block-paste-after-linebreak
Open

[lexical] Bug Fix: Preserve pasted blocks after consecutive line breaks#8890
wanxiankai wants to merge 1 commit into
facebook:mainfrom
wanxiankai:fix/preserve-block-paste-after-linebreak

Conversation

@wanxiankai

Copy link
Copy Markdown

Description

Pasting multiple blocks after two consecutive soft line breaks currently merges the first pasted block into the surrounding paragraph. This drops block semantics, such as a heading's tag.

Treat consecutive soft line breaks as a block boundary so the first pasted block retains its type. The selection remains at the end of the pasted content, before the original trailing text.

Closes #4815

Test plan

Before

Issue4815Repro.test.ts fails because the heading is merged into the surrounding paragraph.

After

Issue4815Repro.test.ts passes, preserving the heading block and selection. A second assertion confirms the existing single-line-break merge behavior is unchanged.

@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Jul 31, 2026 1:36am
lexical-playground Ready Ready Preview Jul 31, 2026 1:36am

Request Review

@meta-cla

meta-cla Bot commented Jul 29, 2026

Copy link
Copy Markdown

Hi @wanxiankai!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Jul 29, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla 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 29, 2026
@meta-cla

meta-cla Bot commented Jul 29, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jul 30, 2026

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The cursor ends up in the wrong location after pasting

## Description

Treat consecutive soft line breaks as a block boundary when inserting blocks so pasted blocks do not merge into either side of the surrounding paragraph. This preserves block formatting and leaves the cursor at the end of the pasted content.

Closes facebook#4815

## Test plan

### Before

Issue4815Repro.test.ts fails because the heading is merged into the surrounding paragraph or the final pasted paragraph is merged with the original trailing text, moving the cursor to the wrong location.

### After

Issue4815Repro.test.ts passes, preserving both pasted block boundaries, the pasted-content selection, and the existing single-line-break merge behavior.
@wanxiankai

Copy link
Copy Markdown
Author

Thanks for catching this. I reproduced it with the playground state from #4815. The previous version only prevented the first pasted block from merging into the left side; the final pasted paragraph could still merge with the original trailing content, so the block boundary and cursor result were incomplete.

Updated in 1edace8:

  • preserve pasted blocks on both sides of the consecutive-soft-break boundary;
  • keep the original trailing paragraph separate;
  • leave the selection at the end of the pasted paragraph;
  • retain the existing single-soft-break merge behavior.

The regression test now asserts the four resulting blocks (paragraph, heading, paragraph, paragraph) and the exact collapsed selection. I also rebased onto the latest main; the targeted unit test passes (2/2).

@wanxiankai
wanxiankai requested a review from etrepum July 31, 2026 01:38
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. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Pasting over linebreaks puts content in different places

2 participants