[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) <dmo@odoo.com>
This commit is contained in:
Sébastien Geelen (sge)
2021-04-09 10:48:31 +00:00
parent d7c4362319
commit ef83c6af8f
@@ -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.
*