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 5844609fa9b..c9a9a4634bc 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1927,8 +1927,11 @@ var SnippetsMenu = Widget.extend({ * when the DOM elements must be in an editable environment to be * considered (@see noCheck), this is true if the DOM elements' * parent must also be in an editable environment to be considered. + * @param {string} excludeParent + * jQuery selector that the parents of DOM elements must *not* match + * to be considered as potential snippet. */ - _computeSelectorFunctions: function (selector, exclude, target, noCheck, isChildren) { + _computeSelectorFunctions: function (selector, exclude, target, noCheck, isChildren, excludeParent) { var self = this; exclude += `${exclude && ', '}.o_snippet_not_selectable`; @@ -1942,6 +1945,12 @@ var SnippetsMenu = Widget.extend({ return oldFilter.apply(this) && $(this).find(target).length !== 0; }; } + if (excludeParent) { + const oldFilter = filterFunc; + filterFunc = function () { + return oldFilter.apply(this) && !$(this).parent().is(excludeParent); + }; + } // Prepare the functions var functions = { @@ -1994,10 +2003,12 @@ var SnippetsMenu = Widget.extend({ this.templateOptions = []; var selectors = []; var $styles = $html.find('[data-selector]'); + const snippetAdditionDropIn = $styles.filter('#so_snippet_addition').data('drop-in'); $styles.each(function () { var $style = $(this); var selector = $style.data('selector'); var exclude = $style.data('exclude') || ''; + const excludeParent = $style.attr('id') === "so_content_addition" ? snippetAdditionDropIn : ''; var target = $style.data('target'); var noCheck = $style.data('no-check'); var optionID = $style.data('js') || $style.data('option-name'); // used in tour js as selector @@ -2008,7 +2019,7 @@ var SnippetsMenu = Widget.extend({ 'base_target': target, 'selector': self._computeSelectorFunctions(selector, exclude, target, noCheck), '$el': $style, - 'drop-near': $style.data('drop-near') && self._computeSelectorFunctions($style.data('drop-near'), '', false, noCheck, true), + 'drop-near': $style.data('drop-near') && self._computeSelectorFunctions($style.data('drop-near'), '', false, noCheck, true, excludeParent), 'drop-in': $style.data('drop-in') && self._computeSelectorFunctions($style.data('drop-in'), '', false, noCheck), 'data': _.extend({string: $style.attr('string')}, $style.data()), };