From a45d1a00eb562d80d6999b7660056a360c20698a Mon Sep 17 00:00:00 2001 From: Nulo Date: Tue, 18 Apr 2023 19:19:11 -0300 Subject: [PATCH] =?UTF-8?q?no=20deduplicar=20links=20que=20no=20est=C3=A1n?= =?UTF-8?q?=20al=20lado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor/menubar/Linking.svelte | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/editor/menubar/Linking.svelte b/src/editor/menubar/Linking.svelte index 5b6fa76..c833cc0 100644 --- a/src/editor/menubar/Linking.svelte +++ b/src/editor/menubar/Linking.svelte @@ -31,12 +31,14 @@ function getLinks(node) { /** @type {Link[]} */ let links = []; + let lastWasLinkMark = false; node.descendants((node) => { for (const mark of node.marks) { const content = node.textContent; // no repetir marks interrumpidas por otras marks const lastLink = links[links.length - 1] || null; if ( + lastWasLinkMark && lastLink && ("href" in lastLink ? lastLink.href === mark.attrs.href @@ -51,14 +53,19 @@ content, href: mark.attrs.href, }); + lastWasLinkMark = true; } else if (mark.type === schema.marks.internal_link) { links.push({ type: "internal", content, id: mark.attrs.id, }); + lastWasLinkMark = true; + } else { + lastWasLinkMark = false; } } + if (node.marks.length == 0) lastWasLinkMark = false; }); return links; }