feat: improve links behavior in the editor (#6612)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-09-18 13:59:30 +07:00 committed by GitHub
parent fc48297b70
commit 78e601ff43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 7 deletions

View File

@ -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')
}}

View File

@ -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()
}
})
})
}