-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Edit Link modal fix #5551
Edit Link modal fix #5551
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
I'm not sure how to solve the failed test, essentially it looks like assertSelection is failing, but I'm not exactly sure what the Array is saying. ` - Expected - 2
I've tested it and the only change I see is when you click the hyperlink icon the focus offset is 0 instead of 6, but the selection is essentially the same otherwise. I'm not sure how the change alters the selection since all it does is add additional checks for determining when isLink should be true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I wonder if it would be easier and more performant to look at the selection anchor
and focus
instead to determine whether the link is in between boundaries.
const linkNodes = selection.getNodes().filter((selectedNode) => { | ||
if ( | ||
$isLinkNode(selectedNode.getParent()) || | ||
$isAutoLinkNode(selectedNode.getParent()) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful when using .getParent
directly, the immediate parent doesn't necessarily have to be the Link. For example, when using CharacterLimit ?isCharLimit=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I will look into this.
I thought about that, but I figured if you select a lone text node in between two link nodes the modal would still pop up. |
@HarrySIV You're right, what about, we loop all the nodes, find |
@zurfyx I'll try that |
Oh, @zurfyx , there was the problem that if you select all, you select the top paragraph node which doesn't have a link node ancestor, which is why I made the search for any node that wasn't the parent of a link node, or have a link node as a parent. I'll try out your suggestion and see what I can do to catch the paragraph node. |
Good point, I think that what you're referring to is a confusing behavior from the browser. The selection is moved to the previous ElementNode even when it's selected at the very end. What do you think of our own custom |
I think I fixed the issue. |
Would it make sense to move the selection and focusNode declarations out of updateToolbar, so that if the focus is not on a LinkNode, we can return out of the useEffect hook so as not to go through the .find method every time selection changes? |
… node isn't being focused
The React re-renderering involved in I still think that this complex problem might help from some utility function to optimize for the best performance without making the product code complicated but happy to merge this PR as is right now. Thank you for working on this! |
That's certainly something I could take a crack at, like the custom getNodes() function you were mentioning? Where would it live, in selection, utils, link? |
@HarrySIV I'm looking at the code in this PR, and I'm struggling to understand this condition: if (
!linkNode?.is(focusLinkNode) &&
!autoLinkNode?.is(focusAutoLinkNode) &&
!linkNode &&
!autoLinkNode &&
!$isLineBreakNode(node)
) {
return node;
} First it tests It seems like this wants to be either if (
!linkNode?.is(focusLinkNode) &&
!autoLinkNode?.is(focusAutoLinkNode) &&
!$isLineBreakNode(node)
) {
return node;
} or if (
!linkNode &&
!autoLinkNode &&
!$isLineBreakNode(node)
) {
return node;
} but it's also possibly I'm misunderstanding entirely 🤷♂️ |
Hi @agriffis , |
…pans further than the link Backports facebook/lexical#5551
This PR fixes #4064 by searching the selected nodes for a node whose parent is not a auto/link node and sets isLink accordingly.
Edit: I forgot to mention the css needs updating with this fix as the text toolbar still makes space for the link toolbar, but I couldn't figure out how the styling was being added.