[IMP] web_editor: select siblings when block is removed

CONTEXT: Within a container, delete a block which has a sibling.

The actual behaviour is to select the container after deletion.

The goal of this commit is to select the previous sibling (if exists),
or next one. Otherwise the parent element will be selected (default behaviour).

task-2431506

closes odoo/odoo#64875

Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
xO-Tx
2021-01-26 18:17:17 +00:00
parent bccfe66486
commit 2cdd95f140
@@ -316,7 +316,13 @@ var SnippetEditor = Widget.extend({
});
});
this.trigger_up('go_to_parent', {$snippet: this.$target});
const parent = this.$target[0].parentElement;
const nextSibling = this.$target[0].nextElementSibling;
const previousSibling = this.$target[0].previousElementSibling;
this.trigger_up('activate_snippet', {
$snippet: $(previousSibling || nextSibling || parent)
});
var $parent = this.$target.parent();
this.$target.find('*').addBack().tooltip('dispose');
this.$target.remove();
@@ -658,7 +664,7 @@ var SnippetEditor = Widget.extend({
}
}
this.trigger_up('go_to_parent', {$snippet: this.$target});
this.trigger_up('activate_snippet', {$snippet: this.$target.parent()});
this.trigger_up('activate_insertion_zones', {
$selectorSiblings: $selectorSiblings,
$selectorChildren: $selectorChildren,
@@ -921,7 +927,6 @@ var SnippetsMenu = Widget.extend({
'deactivate_snippet': '_onDeactivateSnippet',
'drag_and_drop_stop': '_onDragAndDropStop',
'get_snippet_versions': '_onGetSnippetVersions',
'go_to_parent': '_onGoToParent',
'remove_snippet': '_onRemoveSnippet',
'snippet_edition_request': '_onSnippetEditionRequest',
'snippet_editor_destroyed': '_onSnippetEditorDestroyed',
@@ -2333,17 +2338,6 @@ var SnippetsMenu = Widget.extend({
await this._destroyEditors($modal.length ? $modal : null);
await this._activateSnippet(ev.data.$snippet);
},
/**
* Called when a snippet editor asked to disable itself and to enable its
* parent instead.
*
* @private
* @param {OdooEvent} ev
*/
_onGoToParent: function (ev) {
ev.stopPropagation();
this._activateSnippet(ev.data.$snippet.parent());
},
/**
* @private
*/