Skip to content

[lexical] Bug Fix: Preserve paragraph alignment when pasting#8102

Open
aldoprogrammer wants to merge 7 commits intofacebook:mainfrom
aldoprogrammer:fix/paste-preserve-paragraph-alignment-8101
Open

[lexical] Bug Fix: Preserve paragraph alignment when pasting#8102
aldoprogrammer wants to merge 7 commits intofacebook:mainfrom
aldoprogrammer:fix/paste-preserve-paragraph-alignment-8101

Conversation

@aldoprogrammer
Copy link
Contributor

Description

Fixes paste alignment loss when copying from non-left aligned paragraphs. Covers both full paragraph and text-only selection; pasted content retains original alignment.Tests added for HTML/JSON paste and copy/paste scenarios.

Closes #8101

Test plan

Before

Can't persist the alignment copied text

After

Demo

@vercel
Copy link

vercel bot commented Jan 29, 2026

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Feb 6, 2026 6:28pm
lexical-playground Ready Ready Preview, Comment Feb 6, 2026 6:28pm

Request Review

@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 Jan 29, 2026
…ethod for better readability and maintainability
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

This needs a closer look from someone to come up with a better suggestion, but I don't think this is the right approach to solve this problem

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

The logic for this one still doesn't seem right, any transformation to the JSON should be happening during export rather than after

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jan 31, 2026
…node types and adding a new method to extract child nodes based on selection. This improves flexibility in handling different node formats.
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

This looks like the right approach! There are merge conflicts with the tests that need to be resolved before it can be approved

…paragraph-alignment-8101

# Conflicts:
#	packages/lexical/src/nodes/__tests__/unit/LexicalParagraphNode.test.ts
etrepum
etrepum previously approved these changes Feb 6, 2026
@etrepum etrepum dismissed their stale review February 6, 2026 19:25

On further checks discovered some unexpected behavior when copying partial paragraphs

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

This has unexpected behavior when copying partial paragraphs

Screen.Recording.2026-02-06.at.11.29.09.mov

): boolean {
const formatType = this.getFormatType();
return formatType !== '' && formatType !== 'left' && formatType !== 'start';
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just did some final checks here and the problem with this approach is that it doesn't verify that the entire paragraph is selected when preserving the alignment. It's unexpected behavior to copy part of a paragraph and then on paste discover that it creates a new paragraph instead of just copying that text.

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: Text alignment is lost on copy-paste

2 participants

Comments