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 be270c36882..f2d6a2b40d5 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -2123,6 +2123,14 @@ var SnippetsMenu = Widget.extend({ // the invisible DOM list if needed. await this._updateInvisibleDOM(); }, + /** + * Public implementation of _execWithLoadingEffect. + * + * @see this._execWithLoadingEffect for parameters + */ + execWithLoadingEffect(action, contentLoading = true, delay = 500) { + return this._execWithLoadingEffect(...arguments); + }, //-------------------------------------------------------------------------- // Private diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 171dc161046..64f2de6e444 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -308,7 +308,14 @@ const Wysiwyg = Widget.extend({ $el.selectElement(); if (!$el.parent().hasClass('o_stars')) { - self.openMediaDialog(params); + // Waiting for all the options to be initialized before + // opening the media dialog and only if the media has not + // been deleted in the meantime. + self.waitForEmptyMutexAction().then(() => { + if ($el[0].parentElement) { + self.openMediaDialog(params); + } + }); } } }); @@ -1422,6 +1429,18 @@ const Wysiwyg = Widget.extend({ getInSelection(selector) { return getInSelection(this.odooEditor.document, selector); }, + /** + * Adds an empty action in the mutex. Can be used to wait for some options + * to be initialized before doing something else. + * + * @returns {Promise} + */ + waitForEmptyMutexAction() { + if (this.snippetsMenu) { + return this.snippetsMenu.execWithLoadingEffect(() => null, false); + } + return Promise.resolve(); + }, //-------------------------------------------------------------------------- // Private