Skip to content

Commit abddce2

Browse files
committed
[FIX] html_editor: link popover not disappearing on clicking other element
1 parent 48edd7d commit abddce2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

addons/html_editor/static/src/main/link/link_plugin.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,23 @@ export class LinkPlugin extends Plugin {
273273
}
274274
}
275275
});
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+
});
276293
// link creation is added to the command service because of a shortcut conflict,
277294
// as ctrl+k is used for invoking the command palette
278295
this.unregisterLinkCommandCallback = this.services.command.add(
@@ -643,6 +660,7 @@ export class LinkPlugin extends Plugin {
643660
}
644661

645662
handleSelectionChange(selectionData) {
663+
this.lastSelectionData = selectionData;
646664
const selection = selectionData.editableSelection;
647665
if (
648666
this._isNavigatingByMouse &&

0 commit comments

Comments
 (0)