From 78e601ff433c84006644751dffb222e0d3331acf Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Wed, 18 Sep 2024 13:59:30 +0700 Subject: [PATCH] feat: improve links behavior in the editor (#6612) Signed-off-by: Alexander Onnikov --- .../src/components/LinkPopup.svelte | 4 +++- .../text-editor-resources/src/kits/default-kit.ts | 15 +++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/text-editor-resources/src/components/LinkPopup.svelte b/plugins/text-editor-resources/src/components/LinkPopup.svelte index cacaaa7515..cd7ef28097 100644 --- a/plugins/text-editor-resources/src/components/LinkPopup.svelte +++ b/plugins/text-editor-resources/src/components/LinkPopup.svelte @@ -27,13 +27,15 @@ function save (): void { dispatch('update', link) } + + $: canSave = link === '' || URL.canParse(link) { dispatch('close') }} diff --git a/plugins/text-editor-resources/src/kits/default-kit.ts b/plugins/text-editor-resources/src/kits/default-kit.ts index facd5681dc..84a700525c 100644 --- a/plugins/text-editor-resources/src/kits/default-kit.ts +++ b/plugins/text-editor-resources/src/kits/default-kit.ts @@ -73,11 +73,14 @@ export const DefaultKit = Extension.create({ export async function formatLink (editor: Editor): Promise { const link = editor.getAttributes('link').href - showPopup(LinkPopup, { link }, undefined, undefined, (newLink) => { - if (newLink === '') { - editor.chain().focus().extendMarkRange('link').unsetLink().run() - } else { - editor.chain().focus().extendMarkRange('link').setLink({ href: newLink }).run() - } + // give editor some time to handle blur event + setTimeout(() => { + showPopup(LinkPopup, { link }, undefined, undefined, (newLink) => { + if (newLink === '') { + editor.chain().focus().extendMarkRange('link').unsetLink().run() + } else { + editor.chain().focus().extendMarkRange('link').setLink({ href: newLink }).run() + } + }) }) }