From 2136ea5646d77869469a463db4ecd32f0f20ae1e Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 12 Jul 2019 12:54:25 +0000 Subject: [PATCH] [FIX] web_editor, website: consistently apply undo on CTRL-Z MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a bug in Website, that can be reproduced like so: - insert a snippet - insert a char in it - 2x CTRL-Z The second CTRL-Z didn't do anything because Summernote moved the range to the header, which is not editable. This fix moves the range to the first editable element in the editor in these cases, thereby keeping the focus in an editable area, and ensuring that hotkeys still function. The history feature being non-tested as of this version, no test could be added for this fix. closes odoo/odoo#34834 Signed-off-by: Adrien Dieudonné (adr) --- addons/web_editor/static/src/js/wysiwyg/plugin/history.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/web_editor/static/src/js/wysiwyg/plugin/history.js b/addons/web_editor/static/src/js/wysiwyg/plugin/history.js index a60ab41523b..addf6383783 100644 --- a/addons/web_editor/static/src/js/wysiwyg/plugin/history.js +++ b/addons/web_editor/static/src/js/wysiwyg/plugin/history.js @@ -19,6 +19,12 @@ var HistoryPlugin = Plugins.history.extend({ console.error(e); } this.context.invoke('editor.focus'); + var newRange = this.context.invoke('editor.createRange'); + if (!this.options.isEditableNode(newRange.sc)) { + var firstEditableSel = '[contenteditable="true"]:not(":hidden")'; + var sc = this.$editable.find(firstEditableSel)[0]; + this.context.invoke('editor.setRange', sc, 0, sc, 0).select(); + } }, /** * Clear the history.