Skip to content

Commit 4ebe673

Browse files
authored
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".
1 parent bbfff30 commit 4ebe673

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/richtext-lexical/src/features/link/client/plugins/autoLink/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,13 @@ function $createAutoLinkNode_(
187187

188188
const linkNode = $createAutoLinkNode({ fields })
189189
if (nodes.length === 1) {
190-
const split = (
191-
startIndex === 0 ? nodes[0]?.splitText(endIndex) : nodes[0]?.splitText(startIndex, endIndex)
192-
)!
193-
194-
const [linkTextNode, remainingTextNode] = split
190+
const remainingTextNode = nodes[0]!
191+
let linkTextNode: TextNode | undefined
192+
if (startIndex === 0) {
193+
;[linkTextNode] = remainingTextNode.splitText(endIndex)
194+
} else {
195+
;[, linkTextNode] = remainingTextNode.splitText(startIndex, endIndex)
196+
}
195197
if (linkTextNode) {
196198
const textNode = $createTextNode(match.text)
197199
textNode.setFormat(linkTextNode.getFormat())

0 commit comments

Comments
 (0)