From 1d8077c375b9167aa3ee86147a131e2e641a0f91 Mon Sep 17 00:00:00 2001 From: xO-Tx Date: Tue, 2 Mar 2021 14:04:20 +0000 Subject: [PATCH] [FIX] web_editor: fix parent element selection When a block is removed, the parent will be activated. If the parent element is empty and removable: 1) It will be removed too. 2) In '_activateSnippet' method, we look for the right element to be selected using the block's parent (removed from the DOM...). The goal of this commit is to fix this behaviour by computing the selected element before parent removal. task-2431506 closes odoo/odoo#67354 X-original-commit: 1d483ab5e2f9bba0fd86c6fe4595a9959b2f125d Signed-off-by: Quentin Smetz (qsm) --- .../static/src/js/editor/snippets.editor.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 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 4802934cb43..c1d1c10f2e5 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1482,18 +1482,20 @@ var SnippetsMenu = Widget.extend({ if ($snippet && !$snippet.is(':visible')) { return; } + // Take the first parent of the provided DOM (or itself) which + // should have an associated snippet editor. + // It is important to do that before the mutex exec call to compute it + // before potential ancestor removal. + if ($snippet && $snippet.length) { + $snippet = globalSelector.closest($snippet); + } const exec = previewMode ? action => this._mutex.exec(action) : action => this._execWithLoadingEffect(action, false); return exec(() => { return new Promise(resolve => { - // Take the first parent of the provided DOM (or itself) which - // should have an associated snippet editor and create + enable it. if ($snippet && $snippet.length) { - $snippet = globalSelector.closest($snippet); - if ($snippet.length) { - return this._createSnippetEditor($snippet).then(resolve); - } + return this._createSnippetEditor($snippet).then(resolve); } resolve(null); }).then(editorToEnable => {