From 85b1592b808a31e30c07c33a816e4159a953dcd5 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Thu, 28 Jul 2022 15:40:11 +0000 Subject: [PATCH] [FIX] web_editor: prevent toolbar disappear on click link tools button When clicking the link tools button, the listener on `body` clicks is triggered and we check if the toolbar should appear or be hidden. This check should be skipped whenever we click in the toolbar but this was checked via the selection on the global document rather that on the editable's owner document, resulting in an oft-empty selection object. As consequence, the checks were done and the toolbar was hidden, whereas it should remain shown. task-2921844 X-original-commit: f74184b4f98772949040eeea94e389b425fc3265 Part-of: odoo/odoo#97973 --- .../static/src/js/editor/snippets.editor.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 826d406c993..997ba0d11a7 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -3472,19 +3472,18 @@ var SnippetsMenu = Widget.extend({ _checkEditorToolbarVisibility: function (e) { const $toolbarContainer = this.$('#o_we_editor_toolbar_container'); const $toolbarTableContainer = this.$('#o-we-editor-table-container'); - const docSelection = document.getSelection(); - const $currentSelectionTarget = docSelection && docSelection.rangeCount > 0 ? $(docSelection.getRangeAt(0).commonAncestorContainer) : $(); - // Do not toggle visibility if the target is inside the toolbar ( eg. during link edition). + const selection = this.options.wysiwyg.odooEditor.document.getSelection(); + const range = selection && selection.rangeCount && selection.getRangeAt(0); + const $currentSelectionTarget = $(range && range.commonAncestorContainer); + // Do not toggle visibility if the target is inside the toolbar ( eg. + // during link edition). if ($currentSelectionTarget.closest('#o_we_editor_toolbar_container').length || (e && $(e.target).closest('#o_we_editor_toolbar_container').length) ) { return; } - - const selection = this.options.wysiwyg.odooEditor.document.getSelection(); - const range = selection && selection.rangeCount && selection.getRangeAt(0); if (!range || - !$(range.commonAncestorContainer).parents('#wrapwrap, .iframe-editor-wrapper .o_editable').length || + !$currentSelectionTarget.parents('#wrapwrap, .iframe-editor-wrapper .o_editable').length || $(selection.anchorNode).parent('[data-oe-model]:not([data-oe-type="html"]):not([data-oe-field="arch"]):not([data-oe-translation-id])').length || $(selection.focusNode).parent('[data-oe-model]:not([data-oe-type="html"]):not([data-oe-field="arch"]):not([data-oe-translation-id])').length || (e && $(e.target).closest('.fa, img').length ||