[FIX] web_editor: postprocess snippet once added through powerbox
Whenever adding a snippet from the powerbox, the postprocessing was not made. This could result in unexpected behavior of the snippet. Task-2601600 closes odoo/odoo#82694 X-original-commit: bcbf8e59c83200cb079ef15cb1fa5f7783023d88 Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user