From f6bbc40fbe16ea5ab01ad03b8e1519c4e559bf6d Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Wed, 20 Jun 2018 15:14:08 +0200 Subject: [PATCH] [FIX] web_editor: reset snippet editors on snippet move As indicated in a code comment, destroying and rebuilding all snippet editors when a snippet is moved is more accurate as the snippet options may depend on the new locations in a way the 'onMove' callback cannot handle. That operation seemed however too costly for no visual benefit at the time. Now, not implementing it is a source of bugs and redundant code (as with the new "number of columns" option which is not properly updated once a column is moved in another row), so this commit implements the feature. This also allows for some improvement: the 'cleanForSave' part of snippet editors is always performed when they are destroyed. If this proves to be ok and safe, we might want to backport this in previous versions. --- .../static/src/js/editor/snippets.editor.js | 19 +++++++++++-------- 1 file changed, 11 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 708f576ebc8..cc59d8af59b 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -90,6 +90,7 @@ var SnippetEditor = Widget.extend({ * @override */ destroy: function () { + this.cleanForSave(); this._super.apply(this, arguments); this.$target.removeData('snippet-editor'); }, @@ -634,9 +635,7 @@ var SnippetsMenu = Widget.extend({ */ cleanForSave: function () { this.trigger_up('ready_to_clean_for_save'); - _.each(this.snippetEditors, function (snippetEditor) { - snippetEditor.cleanForSave(); - }); + this._destroyEditors(); this.$editable.find('[contentEditable]') .removeAttr('contentEditable') @@ -817,6 +816,14 @@ var SnippetsMenu = Widget.extend({ } return $.when(); }, + /** + * @private + */ + _destroyEditors: function () { + _.each(this.snippetEditors, function (snippetEditor) { + snippetEditor.destroy(); + }); + }, /** * Updates the cover dimensions of the current snippet editor. * @@ -1355,15 +1362,11 @@ var SnippetsMenu = Widget.extend({ /** * Called when a snippet has moved in the page. * - * @todo technically, as a snippet has been moved, all editors should be - * destroyed as their snippet options may not correspond to their - * selector anymore. However this should rarely (maybe never ?) be the case, - * so we might not want to do this as it would slow the editor. - * * @private * @param {OdooEvent} ev */ _onDragAndDropStop: function (ev) { + this._destroyEditors(); this._activateSnippet(ev.data.$snippet); }, /**