From dd58fbf457d5e1d7e58b1156fa6ef9607ab61f85 Mon Sep 17 00:00:00 2001 From: Dominik Biedebach Date: Fri, 30 Sep 2022 04:36:20 +0200 Subject: [PATCH] fix(extension/link): :bug: fix last word value not being passed through when undefined --- packages/extension-link/src/helpers/autolink.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/extension-link/src/helpers/autolink.ts b/packages/extension-link/src/helpers/autolink.ts index d089e7b12..6a8c5e035 100644 --- a/packages/extension-link/src/helpers/autolink.ts +++ b/packages/extension-link/src/helpers/autolink.ts @@ -89,9 +89,18 @@ export function autolink(options: AutolinkOptions): Plugin { if (textBlock && textBeforeWhitespace) { const wordsBeforeWhitespace = textBeforeWhitespace.split(' ').filter(s => s !== '') + + if (wordsBeforeWhitespace.length <= 0) { + return false + } + const lastWordBeforeSpace = wordsBeforeWhitespace[wordsBeforeWhitespace.length - 1] const lastWordAndBlockOffset = textBlock.pos + textBeforeWhitespace.lastIndexOf(lastWordBeforeSpace) + if (!lastWordBeforeSpace) { + return false + } + find(lastWordBeforeSpace) .filter(link => link.isLink) .filter(link => {