From d049e3d7d77c8de9d787e3e08caacafec2fc6efb Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 17 Dec 2021 11:57:59 +0000 Subject: [PATCH] [FIX] web_editor: ensure snippet selection is kept when acting in it The snippet selection was lost on every action in mass mailing. The code that prevents that was checking if the target of a click was the body element but for mass mailing we needed to be a little bit more restrictive since the editable area is not the body itself and we want to actually prevent changing the snippet selection when the target is the iframe target as well. Since the mailing itself has a options, the sidebar is actually never empty and therefore removing a snippet doesn't bring us back to the block tab. Since therefore also ensures that we actually do. task-2716397 X-original-commit: ecdb71bf6a566f5f6c294904e84f2132561dbb3c Part-of: odoo/odoo#81662 --- .../web_editor/static/src/js/editor/snippets.editor.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 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 f9b0e30e0e6..0c41f46d843 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -460,9 +460,14 @@ var SnippetEditor = Widget.extend({ // first, destroying the related editors and not calling onBlur... to // check if this has always been like this or not and this should be // unit tested. - const parent = this.$target[0].parentElement; + let parent = this.$target[0].parentElement; const nextSibling = this.$target[0].nextElementSibling; const previousSibling = this.$target[0].previousElementSibling; + if ($(parent).is('.o_editable:not(body)')) { + // If we target the editable, we want to reset the selection to the + // body. If the editable has options, we do not want to show them. + parent = $(parent).closest('body'); + } this.trigger_up('activate_snippet', { $snippet: $(previousSibling || nextSibling || parent) }); @@ -1293,7 +1298,7 @@ var SnippetsMenu = Widget.extend({ if (!$target.closest('we-button, we-toggler, we-select, .o_we_color_preview').length) { this._closeWidgets(); } - if (!$target.closest('body > *').length) { + if (!$target.closest('body > *').length || $target.is('#iframe_target')) { return; } if ($target.closest(this._notActivableElementsSelector).length) {