diff options
| author | qsm-odoo <qsm@odoo.com> | 2018-06-20 13:13:15 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2018-10-30 13:06:50 +0000 |
| commit | 1058c3cb30c6b1a89845f5e85ec3e0c9f1cbc2d2 (patch) | |
| tree | 0a7d3343b91a1e7875e8a0f643c760ee84553c1c /addons/web_editor | |
| parent | 3219171babf0b400b771be37738ad314d9c7c66f (diff) | |
[REF] web_editor: improve code for snippet editor activation
closes odoo/odoo#28292
Diffstat (limited to 'addons/web_editor')
| -rw-r--r-- | addons/web_editor/static/src/js/editor/snippets.editor.js | 20 |
1 files changed, 11 insertions, 9 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 c5bc3b9bace..d5bb2c3b696 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -782,7 +782,8 @@ var SnippetsMenu = Widget.extend({ * @param {jQuery|false} $snippet * The DOM element whose editor need to be enabled. Only disable the * current one if false is given. - * @returns {Deferred} (might be async when an editor must be created) + * @returns {Deferred<SnippetEditor>} + * (might be async when an editor must be created) */ _activateSnippet: function ($snippet) { if ($snippet) { @@ -790,25 +791,26 @@ var SnippetsMenu = Widget.extend({ $snippet = globalSelector.closest($snippet); } if (this.$activeSnippet && this.$activeSnippet[0] === $snippet[0]) { - return $.when(); + return $.when($snippet.data('snippet-editor')); } } + var editor = null; if (this.$activeSnippet) { - if (this.$activeSnippet.data('snippet-editor')) { - this.$activeSnippet.data('snippet-editor').toggleFocus(false); + editor = this.$activeSnippet.data('snippet-editor'); + if (editor) { + editor.toggleFocus(false); } this.$activeSnippet = false; } if ($snippet && $snippet.length) { var self = this; - return this._createSnippetEditor($snippet).then(function () { + return this._createSnippetEditor($snippet).then(function (editor) { self.$activeSnippet = $snippet; - if (self.$activeSnippet.data('snippet-editor')) { - self.$activeSnippet.data('snippet-editor').toggleFocus(true); - } + editor.toggleFocus(true); + return editor; }); } - return $.when(); + return $.when(editor); }, /** * @private |
