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 b9e59db8b79..645b797fd84 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1569,6 +1569,38 @@ var SnippetsMenu = Widget.extend({ return this._activateSnippet($snippet); }, + /** + * Postprocesses a snippet node when it has been inserted in the dom. + * + * @param {jQuery} $target + * @returns {Promise} + */ + callPostSnippetDrop: async function ($target) { + // First call the onBuilt of all options of each item in the snippet + // (and so build their editor instance first). + await this._callForEachChildSnippet($target, function (editor, $snippet) { + return editor.buildSnippet(); + }); + // The snippet is now fully built, notify the editor for changed + // content. + $target.trigger('content_changed'); + + // Now notifies that a snippet was dropped (at the moment, useful to + // start public widgets for instance (no saved content)). + await this._mutex.exec(() => { + const proms = []; + this.trigger_up('snippet_dropped', { + $target: $target, + addPostDropAsync: prom => proms.push(prom), + }); + return Promise.all(proms); + }); + + // Lastly, ensure that the snippets or its related parts are added to + // the invisible DOM list if needed. + await this._updateInvisibleDOM(); + }, + //-------------------------------------------------------------------------- // Private //-------------------------------------------------------------------------- @@ -2515,32 +2547,7 @@ var SnippetsMenu = Widget.extend({ // (mutexed as well). dragAndDropResolve(); - // First call the onBuilt of all options of each - // item in the snippet (and so build their editor - // instance first). - await self._callForEachChildSnippet($target, function (editor, $snippet) { - return editor.buildSnippet(); - }); - // The snippet is now fully built, notify the - // editor for changed content. - $target.trigger('content_changed'); - - // Now notifies that a snippet was dropped (at the - // moment, useful to start public widgets for - // instance (no saved content)). - await self._mutex.exec(() => { - const proms = []; - self.trigger_up('snippet_dropped', { - $target: $target, - addPostDropAsync: prom => proms.push(prom), - }); - return Promise.all(proms); - }); - - // Lastly, ensure that the snippets or its related - // parts are added to the invisible DOM list if - // needed. - await self._updateInvisibleDOM(); + await self.callPostSnippetDrop($target); // Restore editor to its normal edition state, also // make sure the undroppable snippets are updated. diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index b0549267710..dae6ac6bf71 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1645,10 +1645,13 @@ const Wysiwyg = Widget.extend({ _getSnippetsCommands: function () { const snippetCommandCallback = (selector) => { const $separatorBody = $(selector); - const $clonedBody = $separatorBody.clone(); + const $clonedBody = $separatorBody.clone().removeClass('oe_snippet_body'); const range = getDeepRange(this.odooEditor.editable); const block = closestElement(range.endContainer, 'p, div, ol, ul, cl, h1, h2, h3, h4, h5, h6'); - block && block.after($clonedBody[0]); + if (block) { + block.after($clonedBody[0]); + this.snippetsMenu.callPostSnippetDrop($clonedBody); + } }; return [ {