From 53b4afe747ab6ec2cfc889867e86fb8bc0ac3408 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Wed, 16 Mar 2022 12:54:08 +0000 Subject: [PATCH] [FIX] web_editor: keep content on enter on mobile Before this commit, when hitting enter while not in composition mode, the editor sometimes removed all the content that was added the previous composition. task-4720 closes odoo/odoo#91235 X-original-commit: eddc820417d97b4100a9fb2f9f8934a84bb2417c Signed-off-by: David Monjoie (dmo) --- .../static/lib/odoo-editor/src/OdooEditor.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js index 1ee442858d7..da08af32367 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js @@ -2335,14 +2335,17 @@ export class OdooEditor extends EventTarget { this._lastBeforeInputType === 'insertParagraph'; if (this.keyboardType === KEYBOARD_TYPES.PHYSICAL || !wasCollapsed) { if (ev.inputType === 'deleteContentBackward') { + this._compositionStep(); this.historyRollback(); ev.preventDefault(); this._applyCommand('oDeleteBackward'); } else if (ev.inputType === 'deleteContentForward' || isChromeDeleteforward) { + this._compositionStep(); this.historyRollback(); ev.preventDefault(); this._applyCommand('oDeleteForward'); } else if (ev.inputType === 'insertParagraph' || isChromeInsertParagraph) { + this._compositionStep(); this.historyRollback(); ev.preventDefault(); if (this._applyCommand('oEnter') === UNBREAKABLE_ROLLBACK_CODE) { @@ -2404,6 +2407,7 @@ export class OdooEditor extends EventTarget { this.sanitize(); this.historyStep(); } else if (ev.inputType === 'insertLineBreak') { + this._compositionStep(); this.historyRollback(); ev.preventDefault(); this._applyCommand('oShiftEnter'); @@ -2411,6 +2415,8 @@ export class OdooEditor extends EventTarget { this.sanitize(); this.historyStep(); } + } else if (ev.inputType === 'insertCompositionText') { + this._fromCompositionText = true; } } @@ -2589,6 +2595,17 @@ export class OdooEditor extends EventTarget { this.editable.contains(selection.focusNode); } + /** + * @private + */ + _compositionStep() { + if (this._fromCompositionText) { + this._fromCompositionText = false; + this.sanitize(); + this.historyStep(); + } + } + /** * Returns true if the current selection content is only one ZWS *