[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) <qsm@odoo.com>
This commit is contained in:
xO-Tx
2021-03-05 12:40:43 +00:00
committed by qsm-odoo
parent cda0b9c994
commit 1d8077c375
@@ -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 => {