[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) <dmo@odoo.com>
This commit is contained in:
Nicolas Bayet
2022-05-12 17:35:04 +02:00
parent 6f9110bfb0
commit 53b4afe747
@@ -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
*