From e795186dec8ddfd5826a7c2e26fbef84e2d7e790 Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Tue, 26 Oct 2021 14:38:45 +0000 Subject: [PATCH] [FIX] web_editor: delete unicode character MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when trying to delete one unicode character (e.g. 😍), only one javascript character was delete but one unicode character (e.g. 😍) could be two javascript characters as the javascript string is coded in utf-16. This commit fixes that by calculating the size of one unicode character from the javascript string. Task-2658890 closes odoo/odoo#79071 X-original-commit: fea5b87615077f5f41dec8c4d1480f157bbd26ae Signed-off-by: David Monjoie (dmo) --- .../static/lib/odoo-editor/src/commands/deleteBackward.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/web_editor/static/lib/odoo-editor/src/commands/deleteBackward.js b/addons/web_editor/static/lib/odoo-editor/src/commands/deleteBackward.js index e8e51b31bde..4e1bd054fd0 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/commands/deleteBackward.js +++ b/addons/web_editor/static/lib/odoo-editor/src/commands/deleteBackward.js @@ -35,9 +35,11 @@ Text.prototype.oDeleteBackward = function (offset, alreadyMoved = false) { return; } - // First, split around the character where the backspace occurs - const firstSplitOffset = splitTextNode(this, offset - 1); - const secondSplitOffset = splitTextNode(parentNode.childNodes[firstSplitOffset], 1); + // Get the size of the unicode character to remove. + const charSize = [...this.nodeValue.slice(0, offset)].pop().length; + // Split around the character where the backspace occurs. + const firstSplitOffset = splitTextNode(this, offset - charSize); + const secondSplitOffset = splitTextNode(parentNode.childNodes[firstSplitOffset], charSize); const middleNode = parentNode.childNodes[firstSplitOffset]; // Do remove the character, then restore the state of the surrounding parts.