Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical-link] Fix bug when can't remove link formatting from autolink #6306

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

MaxPlav
Copy link
Contributor

@MaxPlav MaxPlav commented Jun 13, 2024

This PR fixes a bug where a user cannot remove link formatting (unlink) from links created by AutoLinkNode. However, it works for links created by LinkNode. The proposal is to add a flag property in AutoLinkNode to indicate if the link was unlinked. If so, render the link as regular text, keeping styles. The hidden auto-link can become a link again via the Toolbar Link button.

Closes #5607

Test plan

  1. Open https://playground.lexical.dev/
  2. Input to the editor "www.facebook.com".
  3. Check the auto-link is created.
  4. Focus on the link.
  5. Click the delete button on the popup.
  6. The link should transform to the regular text "www.facebook.com".

Before

Screen.Recording.2024-06-13.at.15.18.13.mov

After

Screen.Recording.2024-06-13.at.15.20.36.mov

Copy link

vercel bot commented Jun 13, 2024

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 Jun 14, 2024 5:24pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 14, 2024 5:24pm

@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 Jun 13, 2024
Copy link

github-actions bot commented Jun 13, 2024

size-limit report 📦

Path Size
lexical - cjs 28.31 KB (0%)
lexical - esm 28.13 KB (0%)
@lexical/rich-text - cjs 36.71 KB (0%)
@lexical/rich-text - esm 28.09 KB (0%)
@lexical/plain-text - cjs 35.4 KB (0%)
@lexical/plain-text - esm 25.33 KB (0%)
@lexical/react - cjs 38.59 KB (+0.02% 🔺)
@lexical/react - esm 29.14 KB (0%)

Copy link
Contributor

@StyleT StyleT left a comment

Choose a reason for hiding this comment

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

LGTM overall! Can you also add some unit & E2E tests pls?

@@ -89,6 +89,11 @@
text-decoration: underline;
cursor: pointer;
}
.PlaygroundEditorTheme__hiddenLink {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that instead of masking <a> tag as "regular" text - we shall simply render "hidden link" as <span>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed that

createDOM(config: EditorConfig): HTMLAnchorElement {
if (this.__isUnlinked) {
// render a link that behaves like a span
const element = document.createElement('a');
Copy link
Contributor

Choose a reason for hiding this comment

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

Simply use span here? Or no wrapper all together?

@StyleT StyleT added the extended-tests Run extended e2e tests on a PR label Jun 13, 2024
@MaxPlav
Copy link
Contributor Author

MaxPlav commented Jun 14, 2024

LGTM overall! Can you also add some unit & E2E tests pls?

hi, sure I've added an e2e test and unit tests. Also now the unlinked AutoLink node is rendered as "span" element. For that I had to update several types of the LinkNode methods, as a return type of the overridden method must be a subtype of the return type in the superclass.

Copy link
Contributor

@StyleT StyleT left a comment

Choose a reason for hiding this comment

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

LGTM!

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: Can't remove link formatting from links added by AutoLinkPlugin
4 participants