@@ -111,14 +111,12 @@ class SelectionTooltip implements PluginView {
111
111
if ( prevState && prevState . doc . eq ( state . doc ) && prevState . selection . eq ( state . selection ) )
112
112
return ;
113
113
114
- const prevTextNode = this . textNode ;
115
114
this . textNode = getTextNode ( view . state ) ;
116
115
117
116
const prevRef = this . textNodeRef ;
118
117
this . updateTextNodeRef ( ) ;
119
118
120
119
if ( ! this . textNode || ! this . textNodeRef ) {
121
- this . removePlaceholderLink ( prevTextNode ) ;
122
120
this . hideTooltip ( ) ;
123
121
return ;
124
122
}
@@ -191,14 +189,9 @@ class SelectionTooltip implements PluginView {
191
189
} ;
192
190
193
191
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 ;
202
195
} ;
203
196
204
197
private cancelPopup ( ) {
@@ -235,11 +228,11 @@ class SelectionTooltip implements PluginView {
235
228
if ( normalizeResult ) {
236
229
const { url} = normalizeResult ;
237
230
const { from, to} = textNode ;
238
- view . dispatch (
239
- view . state . tr . addMark ( from , to , linkType ( view . state . schema ) . create ( { href : url } ) ) ,
240
- ) ;
241
231
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 ) ;
243
236
}
244
237
}
245
238
0 commit comments