[FIX] web_editor: delete unicode character

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) <dmo@odoo.com>
This commit is contained in:
Nicolas Bayet
2021-10-27 14:01:43 +00:00
parent 218e9bb2aa
commit e795186dec
@@ -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.