fix(richtext-lexical): fix bug in $createAutoLinkNode when the link is preceded by a textnode (#11551)

If you type "hello www.world.com" the autlink would remove the word
"hello".
This commit is contained in:
Germán Jabloñski
2025-03-05 15:06:24 -03:00
committed by GitHub
parent bbfff30d41
commit 4ebe67324a

View File

@@ -187,11 +187,13 @@ function $createAutoLinkNode_(
const linkNode = $createAutoLinkNode({ fields }) const linkNode = $createAutoLinkNode({ fields })
if (nodes.length === 1) { if (nodes.length === 1) {
const split = ( const remainingTextNode = nodes[0]!
startIndex === 0 ? nodes[0]?.splitText(endIndex) : nodes[0]?.splitText(startIndex, endIndex) let linkTextNode: TextNode | undefined
)! if (startIndex === 0) {
;[linkTextNode] = remainingTextNode.splitText(endIndex)
const [linkTextNode, remainingTextNode] = split } else {
;[, linkTextNode] = remainingTextNode.splitText(startIndex, endIndex)
}
if (linkTextNode) { if (linkTextNode) {
const textNode = $createTextNode(match.text) const textNode = $createTextNode(match.text)
textNode.setFormat(linkTextNode.getFormat()) textNode.setFormat(linkTextNode.getFormat())