From 2cdd95f140b6ec5f3b95ee19bde2f281de21f337 Mon Sep 17 00:00:00 2001 From: xO-Tx Date: Tue, 26 Jan 2021 18:17:17 +0000 Subject: [PATCH] [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) --- .../static/src/js/editor/snippets.editor.js | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 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 6886b466348..4802934cb43 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -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 */