From ad644d9ae7e55f264dbe7573764d0c4bc0e945a7 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Mon, 9 Aug 2021 10:54:38 +0000 Subject: [PATCH] [FIX] web_editor: properly handle editor enabling and preview mode The editor panel keeps tracks of the SnippetEditor instances which are enabled at the current time. When previewing one (by hovering its UI), that tracking was messed up making onFocus and onBlur calls inconsitent. Part of https://github.com/odoo/odoo/pull/74959 X-original-commit: 0d7e660d8c0941b1af83b08a90d936933287d681 --- .../static/src/js/editor/snippets.editor.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 05f046b6695..2daa9eb3153 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1753,18 +1753,20 @@ var SnippetsMenu = Widget.extend({ return editorToEnable; } - const editorToEnableHierarchy = []; - let current = editorToEnable; - while (current && current.$target) { - editorToEnableHierarchy.push(current); - current = current.getParent(); + if (!previewMode) { + this._enabledEditorHierarchy = []; + let current = editorToEnable; + while (current && current.$target) { + this._enabledEditorHierarchy.push(current); + current = current.getParent(); + } } // First disable all editors... for (let i = this.snippetEditors.length; i--;) { const editor = this.snippetEditors[i]; editor.toggleOverlay(false, previewMode); - if (!previewMode && !editorToEnableHierarchy.includes(editor)) { + if (!previewMode && !this._enabledEditorHierarchy.includes(editor)) { editor.toggleOptions(false); } } @@ -1773,7 +1775,7 @@ var SnippetsMenu = Widget.extend({ if (editorToEnable) { editorToEnable.toggleOverlay(true, previewMode); if (!previewMode && !editorToEnable.displayOverlayOptions) { - const parentEditor = editorToEnableHierarchy.find(ed => ed.displayOverlayOptions); + const parentEditor = this._enabledEditorHierarchy.find(ed => ed.displayOverlayOptions); if (parentEditor) { parentEditor.toggleOverlay(true, previewMode); } @@ -1788,7 +1790,6 @@ var SnippetsMenu = Widget.extend({ }); } - this._enabledEditorHierarchy = editorToEnableHierarchy; return editorToEnable; }); });