From b90b0904f09d969fc51cfa5fca3b7de5ba3675a6 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 17 Mar 2023 13:07:01 +0000 Subject: [PATCH] [FIX] web_editor: properly undo unlink When clicking on a button from the link popover, the popover gets hidden, which pauses the editor's mutation observer until the popover is fully faded out. This is problematic when the button in question calls an editor command which we need to be able to undo, since the mutation observer will still be paused during the command execution. This lets the buttons' listeners handle the hiding of the popover themselves to prevent this race condition. closes odoo/odoo#118248 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/wysiwyg/widgets/link_popover_widget.js | 7 ++++++- .../website/static/src/js/widgets/link_popover_widget.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js index 388b6b6a74f..0de5cfb9d4b 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js @@ -56,6 +56,7 @@ const LinkPopoverWidget = Widget.extend({ type: 'success', message: _t("Link copied to clipboard."), }); + this.popover.hide(); }); // init tooltips & popovers @@ -127,9 +128,11 @@ const LinkPopoverWidget = Widget.extend({ !( hierarchy.includes(this.$target[0]) || (hierarchy.includes(this.$el[0]) && - !hierarchy.some(x => x.tagName && x.tagName === 'A')) + !hierarchy.some(x => x.tagName && x.tagName === 'A' && (x === this.$urlLink[0] || x === this.$fullUrl[0]))) ) ) { + // Note: For buttons of the popover, their listeners should + // handle the hide themselves to avoid race conditions. this.popover.hide(); } } @@ -265,6 +268,7 @@ const LinkPopoverWidget = Widget.extend({ link: this.$target[0], }); ev.stopImmediatePropagation(); + this.popover.hide(); }, /** * Removes the link/anchor. @@ -276,6 +280,7 @@ const LinkPopoverWidget = Widget.extend({ ev.preventDefault(); this.options.wysiwyg.removeLink(); ev.stopImmediatePropagation(); + this.popover.hide(); }, }); diff --git a/addons/website/static/src/js/widgets/link_popover_widget.js b/addons/website/static/src/js/widgets/link_popover_widget.js index 1b357472e1c..e39e3857fbb 100644 --- a/addons/website/static/src/js/widgets/link_popover_widget.js +++ b/addons/website/static/src/js/widgets/link_popover_widget.js @@ -91,6 +91,7 @@ const NavbarLinkPopoverWidget = weWidgets.LinkPopoverWidget.extend({ }); }, }); + this.popover.hide(); }, /** * Opens the menu tree editor. On menu editor save, current page changes