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. *