[REF] web_editor: allow to enable DOM editors only if not already active
Related to https://github.com/odoo/odoo/pull/38997 Related to task-2090180
This commit is contained in:
@@ -696,6 +696,7 @@ var SnippetsMenu = Widget.extend({
|
||||
}
|
||||
this.snippetEditors = [];
|
||||
this._activateSnippetMutex = new concurrency.Mutex();
|
||||
this._enabledEditorHierarchy = [];
|
||||
|
||||
this.setSelectorEditableArea(options.$el, options.selectorEditableArea);
|
||||
},
|
||||
@@ -1048,10 +1049,11 @@ var SnippetsMenu = Widget.extend({
|
||||
* The DOM element whose editor (and its parent ones) need to be
|
||||
* enabled. Only disable the current one if false is given.
|
||||
* @param {boolean} [previewMode=false]
|
||||
* @param {boolean} [ifInactiveOptions=false]
|
||||
* @returns {Promise<SnippetEditor>}
|
||||
* (might be async when an editor must be created)
|
||||
*/
|
||||
_activateSnippet: function ($snippet, previewMode) {
|
||||
_activateSnippet: function ($snippet, previewMode, ifInactiveOptions) {
|
||||
return this._activateSnippetMutex.exec(() => {
|
||||
return new Promise(resolve => {
|
||||
// Take the first parent of the provided DOM (or itself) which
|
||||
@@ -1064,6 +1066,10 @@ var SnippetsMenu = Widget.extend({
|
||||
}
|
||||
resolve(null);
|
||||
}).then(editorToEnable => {
|
||||
if (ifInactiveOptions && this._enabledEditorHierarchy.includes(editorToEnable)) {
|
||||
return editorToEnable;
|
||||
}
|
||||
|
||||
const editorToEnableHierarchy = [];
|
||||
let current = editorToEnable;
|
||||
while (current && current.$target) {
|
||||
@@ -1084,6 +1090,8 @@ var SnippetsMenu = Widget.extend({
|
||||
editorToEnable.toggleOverlay(true, previewMode);
|
||||
editorToEnable.toggleOptions(true);
|
||||
}
|
||||
|
||||
this._enabledEditorHierarchy = editorToEnableHierarchy;
|
||||
return editorToEnable;
|
||||
});
|
||||
});
|
||||
@@ -1618,7 +1626,7 @@ var SnippetsMenu = Widget.extend({
|
||||
* @private
|
||||
*/
|
||||
_onActivateSnippet: function (ev) {
|
||||
this._activateSnippet(ev.data.$snippet, ev.data.previewMode);
|
||||
this._activateSnippet(ev.data.$snippet, ev.data.previewMode, ev.data.ifInactiveOptions);
|
||||
},
|
||||
/**
|
||||
* Called when a child editor asks to operate some operation on all child
|
||||
|
||||
Reference in New Issue
Block a user