diff --git a/src/extensions/markdown/Link/plugins/LinkTooltipPlugin/index.tsx b/src/extensions/markdown/Link/plugins/LinkTooltipPlugin/index.tsx index bcf76a77..0627ae36 100644 --- a/src/extensions/markdown/Link/plugins/LinkTooltipPlugin/index.tsx +++ b/src/extensions/markdown/Link/plugins/LinkTooltipPlugin/index.tsx @@ -111,14 +111,12 @@ class SelectionTooltip implements PluginView { if (prevState && prevState.doc.eq(state.doc) && prevState.selection.eq(state.selection)) return; - const prevTextNode = this.textNode; this.textNode = getTextNode(view.state); const prevRef = this.textNodeRef; this.updateTextNodeRef(); if (!this.textNode || !this.textNodeRef) { - this.removePlaceholderLink(prevTextNode); this.hideTooltip(); return; } @@ -191,14 +189,9 @@ class SelectionTooltip implements PluginView { }; private onOutisdeClick = () => { - // after all updates of the editor state - setTimeout(() => { - if (!this.view.hasFocus()) { - this.removePlaceholderLink(this.textNode); - this.hideTooltip(); - this.manualHidden = false; - } - }); + this.removePlaceholderLink(this.textNode); + this.hideTooltip(); + this.manualHidden = true; }; private cancelPopup() { @@ -235,11 +228,11 @@ class SelectionTooltip implements PluginView { if (normalizeResult) { const {url} = normalizeResult; const {from, to} = textNode; - view.dispatch( - view.state.tr.addMark(from, to, linkType(view.state.schema).create({href: url})), - ); - setTimeout(this.cancelPopup.bind(this)); + const tr = view.state.tr; + tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(to))); + tr.addMark(from, to, linkType(view.state.schema).create({href: url})); + view.dispatch(tr); } }