@@ -273,6 +273,23 @@ export class LinkPlugin extends Plugin {
273
273
}
274
274
}
275
275
} ) ;
276
+ // Some elements can be clicked on without the selection being changed
277
+ // In those cases the overlay closing and opening must be done manually
278
+ this . addDomListener ( this . editable , "click" , ( ev ) => {
279
+ const currentSelection = this . document . getSelection ( ) ;
280
+ if ( ! ev . target . contains ( currentSelection . anchorNode ) ) {
281
+ this . currentOverlay . close ( ) ;
282
+ this . linkInDocument = null ;
283
+ } else if (
284
+ this . lastSelectionData &&
285
+ this . lastSelectionData . documentSelection . anchorNode ===
286
+ currentSelection . anchorNode &&
287
+ this . lastSelectionData . documentSelection . anchorOffset ===
288
+ currentSelection . anchorOffset
289
+ ) {
290
+ this . handleSelectionChange ( this . lastSelectionData ) ;
291
+ }
292
+ } ) ;
276
293
// link creation is added to the command service because of a shortcut conflict,
277
294
// as ctrl+k is used for invoking the command palette
278
295
this . unregisterLinkCommandCallback = this . services . command . add (
@@ -643,6 +660,7 @@ export class LinkPlugin extends Plugin {
643
660
}
644
661
645
662
handleSelectionChange ( selectionData ) {
663
+ this . lastSelectionData = selectionData ;
646
664
const selection = selectionData . editableSelection ;
647
665
if (
648
666
this . _isNavigatingByMouse &&
0 commit comments