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) </script> <Card label={textEditor.string.Link} okLabel={textEditor.string.Save} okAction={save} - canSave + {canSave} on:close={() => { 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<DefaultKitOptions>({ export async function formatLink (editor: Editor): Promise<void> { 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() + } + }) }) }