From 6615bc76b49956009e3e9fb43050c1d4b3efdca8 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 22 Mar 2024 10:58:54 +0100 Subject: [PATCH] [FIX] web_editor: backspace only char with composition menu open When typing in Japanese with Romaji input, a traceback occurred when hitting backspace to remove the only character in the editable while the Japanese character selection menu was open. This is because that case triggers an `insertCompositionText` input event with an empty string, and tries to delete the editable, which is unremovable. Since we called `_applyRawCommand` without wrapping it in `_protect`, the unremovable error caused a traceback instead of a rollback. When fixing that, an other bug appeared, which was the insertion of a `#` character. This was due to the fact that `insertText` was called with empty content, and `insertText` defaulted to the character `#` for no particular reason since the early proof of concept of the editor. task-3134566 closes odoo/odoo#159005 X-original-commit: cb75212d4fe302b54097fbc90da6d6ef8b38205b Signed-off-by: David Monjoie (dmo) Signed-off-by: Antoine Guenet (age) --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 2 +- .../static/src/js/editor/odoo-editor/src/utils/utils.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 190b03f0127..747dea9cad7 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -3705,7 +3705,7 @@ export class OdooEditor extends EventTarget { // Since the unit test Event is not trusted by the browser, we don't // need to undo the char during the unit tests. // @see https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted - this._applyRawCommand('oDeleteBackward'); + this._protect(() => this._applyRawCommand('oDeleteBackward')); } if (latestSelectionInsideEmptyTag) { // Restore the selection inside the empty Element. diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index b5a5125d5f8..a61f35975a5 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -2053,6 +2053,9 @@ export function splitAroundUntil(elements, limitAncestor) { } export function insertText(sel, content) { + if (!content) { + return; + } if (sel.anchorNode.nodeType === Node.TEXT_NODE) { const pos = [sel.anchorNode.parentElement, splitTextNode(sel.anchorNode, sel.anchorOffset)]; setSelection(...pos, ...pos, false);