[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
This commit is contained in:
Antoine Guenet
2022-08-11 17:57:34 +02:00
committed by David Monjoie
parent 457095b393
commit 85b1592b80
@@ -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 ||