From ef83c6af8f3e0c2a7d60bd291f63e275b661aed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Thu, 8 Apr 2021 12:53:25 +0000 Subject: [PATCH] [FIX] web_editor: re-implement focus method Focus is sometimes called on the Wysiwyg class in Note. When the user use TAB to select the next field. Implementation was missing. closes odoo/odoo#69033 X-original-commit: 720c1f38a17ef54cf30e0a52bab5bceed70c2144 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/wysiwyg/wysiwyg.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index c4ff17e4814..34075878beb 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -395,6 +395,25 @@ const Wysiwyg = Widget.extend({ redo: function () { this.odooEditor.historyRedo(); }, + /** + * Focus inside the editor. + * + * Set cursor to the editor latest position before blur or to the last editable node, ready to type. + */ + focus: function () { + if(!this.odooEditor.resetCursorOnLastHistoryCursor()) { + // If the editor don't have an history step to focus to, + // We place the cursor after the end of the editor exiting content. + const range = document.createRange(); + const elementToTarget = this.$editable[0].lastElementChild ? this.$editable[0].lastElementChild : this.$editable[0]; + range.selectNodeContents(elementToTarget); + range.collapse(); + + const selection = this.odooEditor.document.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); + } + }, /** * Start or resume the Odoo field changes muation observers. *