Skip to content

[lexical-link] Feature: Merging two identical links into one node#8168

Open
Jynx2004 wants to merge 17 commits intofacebook:mainfrom
Jynx2004:lexical_link
Open

[lexical-link] Feature: Merging two identical links into one node#8168
Jynx2004 wants to merge 17 commits intofacebook:mainfrom
Jynx2004:lexical_link

Conversation

@Jynx2004
Copy link

Description

In this approach when a user tries to paste any text inside the link , then the text gets injected inside the text of the link directly instead of creation of new TextNode in between the link thus dividing the text of the same link into 2 halfs . This prevents creation of 2 same links .

Closes #8150

Test plan

Before

Screenshot 2026-02-25 135832

After

Screenshot 2026-02-25 135749

@vercel
Copy link

vercel bot commented Feb 25, 2026

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Feb 25, 2026 3:15pm
lexical-playground Ready Ready Preview, Comment Feb 25, 2026 3:15pm

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 Feb 25, 2026
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.

I don't think this code will work correctly and it has no tests

Comment on lines +257 to +260
return (
parentElementAfter.getType() === 'link' &&
parentElementAfter.getType() === parentElementBefore.getType()
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't an acceptable approach. @lexical/clipboard can't depend on @lexical/link, and you can't use getType to check the type of a node since nodes can be subclasses with a different type.

Comment on lines +271 to +281
const textNodes = nodes.filter((node) => $isTextNode(node));

if (textNodes.length > 0) {
const firstText = textNodes[0];
selection.insertText(firstText.getTextContent());
$updateSelectionOnInsert(selection);
}
} else {
selection.insertNodes(nodes);
$updateSelectionOnInsert(selection);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't look correct since all other nodes will be discarded if one TextNode exists. It also ignores any formatting.

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.

Feature: Merging two identical links into one node

2 participants