2025-03-18 19:28:35 +01:00
|
|
|
|
<!DOCTYPE html>
|
2024-11-30 12:20:44 +01:00
|
|
|
|
<script src="../include.js"></script>
|
2025-09-03 16:53:18 +02:00
|
|
|
|
<div id="a" contenteditable>foobar</div>
|
|
|
|
|
|
<div id="b" contenteditable>foo👩🏼❤️👨🏻bar</div>
|
|
|
|
|
|
<div id="c" contenteditable>foo<div contenteditable>bar</div></div>
|
2024-11-30 12:20:44 +01:00
|
|
|
|
<script>
|
|
|
|
|
|
test(() => {
|
2025-09-03 16:53:18 +02:00
|
|
|
|
const testDelete = function (divId, anchorExpression, position) {
|
2025-08-14 15:25:19 -04:00
|
|
|
|
println(`--- ${divId} ---`);
|
|
|
|
|
|
const divElm = document.querySelector(`div#${divId}`);
|
2025-09-03 16:53:18 +02:00
|
|
|
|
println(`Before: ${divElm.innerHTML}`);
|
2024-11-30 12:20:44 +01:00
|
|
|
|
|
2025-08-14 15:25:19 -04:00
|
|
|
|
// Place cursor
|
2025-09-03 16:53:18 +02:00
|
|
|
|
const anchor = anchorExpression(divElm);
|
|
|
|
|
|
getSelection().setBaseAndExtent(anchor, position, anchor, position);
|
2024-11-30 12:20:44 +01:00
|
|
|
|
|
2025-08-14 15:25:19 -04:00
|
|
|
|
// Press backspace
|
|
|
|
|
|
document.execCommand("delete");
|
2024-11-30 12:20:44 +01:00
|
|
|
|
|
2025-09-03 16:53:18 +02:00
|
|
|
|
println(`After: ${divElm.innerHTML}`);
|
2025-08-14 15:25:19 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-03 16:53:18 +02:00
|
|
|
|
testDelete("a", (node) => node.firstChild, 3);
|
|
|
|
|
|
testDelete("b", (node) => node.firstChild, 15);
|
|
|
|
|
|
testDelete("c", (node) => node.childNodes[1].firstChild, 0);
|
2024-11-30 12:20:44 +01:00
|
|
|
|
});
|
|
|
|
|
|
</script>
|