LibWeb: Delete entire graphemes when the delete/backspace key is pressed

We currently delete a single code unit. If the user presses backspace on
a multi code point emoji, they are going to expect the entire emoji to
be removed. This now matches the behavior of Chrome and Firefox.
This commit is contained in:
Timothy Flynn
2025-08-14 15:25:19 -04:00
committed by Jelle Raaijmakers
parent 76bab90812
commit c369f68eff
Notes: github-actions[bot] 2025-08-14 20:22:53 +00:00
8 changed files with 69 additions and 19 deletions

View File

@@ -1,19 +1,25 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<div contenteditable="true">foobar</div>
<div id="a" contenteditable="true">foobar</div>
<div id="b" contenteditable="true">foo👩🏼👨🏻bar</div>
<script>
test(() => {
var divElm = document.querySelector('div');
println(`Before: ${divElm.textContent}`);
const testDelete = function (divId, position) {
println(`--- ${divId} ---`);
const divElm = document.querySelector(`div#${divId}`);
println(`Before: ${divElm.textContent}`);
// Put cursor after 'foo'
var range = document.createRange();
range.setStart(divElm.childNodes[0], 3);
getSelection().addRange(range);
// Place cursor
const node = divElm.childNodes[0];
getSelection().setBaseAndExtent(node, position, node, position);
// Press backspace
document.execCommand('delete');
// Press backspace
document.execCommand("delete");
println(`After: ${divElm.textContent}`);
println(`After: ${divElm.textContent}`);
};
testDelete("a", 3);
testDelete("b", 15);
});
</script>