Skip to content

Commit c4797ef

Browse files
ReFFaTmakhnatkin
andauthored
fix(link): fixed link cursor focus (#648)
Co-authored-by: Sergey Makhnatkin <[email protected]>
1 parent 12abaf9 commit c4797ef

File tree

1 file changed

+7
-14
lines changed
  • src/extensions/markdown/Link/plugins/LinkTooltipPlugin

1 file changed

+7
-14
lines changed

src/extensions/markdown/Link/plugins/LinkTooltipPlugin/index.tsx

+7-14
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,12 @@ class SelectionTooltip implements PluginView {
111111
if (prevState && prevState.doc.eq(state.doc) && prevState.selection.eq(state.selection))
112112
return;
113113

114-
const prevTextNode = this.textNode;
115114
this.textNode = getTextNode(view.state);
116115

117116
const prevRef = this.textNodeRef;
118117
this.updateTextNodeRef();
119118

120119
if (!this.textNode || !this.textNodeRef) {
121-
this.removePlaceholderLink(prevTextNode);
122120
this.hideTooltip();
123121
return;
124122
}
@@ -191,14 +189,9 @@ class SelectionTooltip implements PluginView {
191189
};
192190

193191
private onOutisdeClick = () => {
194-
// after all updates of the editor state
195-
setTimeout(() => {
196-
if (!this.view.hasFocus()) {
197-
this.removePlaceholderLink(this.textNode);
198-
this.hideTooltip();
199-
this.manualHidden = false;
200-
}
201-
});
192+
this.removePlaceholderLink(this.textNode);
193+
this.hideTooltip();
194+
this.manualHidden = true;
202195
};
203196

204197
private cancelPopup() {
@@ -235,11 +228,11 @@ class SelectionTooltip implements PluginView {
235228
if (normalizeResult) {
236229
const {url} = normalizeResult;
237230
const {from, to} = textNode;
238-
view.dispatch(
239-
view.state.tr.addMark(from, to, linkType(view.state.schema).create({href: url})),
240-
);
241231

242-
setTimeout(this.cancelPopup.bind(this));
232+
const tr = view.state.tr;
233+
tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(to)));
234+
tr.addMark(from, to, linkType(view.state.schema).create({href: url}));
235+
view.dispatch(tr);
243236
}
244237
}
245238

0 commit comments

Comments
 (0)