2025-03-18 15:28:35 -03:00
|
|
|
|
<!DOCTYPE html>
|
2026-05-18 08:35:08 -03:00
|
|
|
|
<meta charset="utf-8">
|
2024-11-30 08:20:44 -03:00
|
|
|
|
<script src="../include.js"></script>
|
2025-09-03 11:53:18 -03:00
|
|
|
|
<div id="a" contenteditable>foobar</div>
|
|
|
|
|
|
<div id="b" contenteditable>foo👩🏼❤️👨🏻bar</div>
|
|
|
|
|
|
<div id="c" contenteditable>foo<div contenteditable>bar</div></div>
|
2025-09-15 08:56:19 -03:00
|
|
|
|
<div id="d" contenteditable>foo<br><br><div>bar<br>baz</div></div>
|
|
|
|
|
|
<div id="e" contenteditable><p>foo</p><br><p>bar</p></div>
|
|
|
|
|
|
<div id="f" contenteditable><p><span>abc</span><br></p></div>
|
2024-11-30 08:20:44 -03:00
|
|
|
|
<script>
|
|
|
|
|
|
test(() => {
|
2025-09-15 08:56:19 -03:00
|
|
|
|
const testDelete = function (divId, anchorExpression, start, end = start) {
|
2025-08-14 16:25:19 -03:00
|
|
|
|
println(`--- ${divId} ---`);
|
|
|
|
|
|
const divElm = document.querySelector(`div#${divId}`);
|
2025-09-03 11:53:18 -03:00
|
|
|
|
println(`Before: ${divElm.innerHTML}`);
|
2024-11-30 08:20:44 -03:00
|
|
|
|
|
2025-08-14 16:25:19 -03:00
|
|
|
|
// Place cursor
|
2025-09-03 11:53:18 -03:00
|
|
|
|
const anchor = anchorExpression(divElm);
|
2025-09-15 08:56:19 -03:00
|
|
|
|
getSelection().setBaseAndExtent(anchor, start, anchor, end);
|
2024-11-30 08:20:44 -03:00
|
|
|
|
|
2025-08-14 16:25:19 -03:00
|
|
|
|
// Press backspace
|
|
|
|
|
|
document.execCommand("delete");
|
2024-11-30 08:20:44 -03:00
|
|
|
|
|
2025-09-03 11:53:18 -03:00
|
|
|
|
println(`After: ${divElm.innerHTML}`);
|
2025-08-14 16:25:19 -03:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-03 11:53:18 -03:00
|
|
|
|
testDelete("a", (node) => node.firstChild, 3);
|
|
|
|
|
|
testDelete("b", (node) => node.firstChild, 15);
|
|
|
|
|
|
testDelete("c", (node) => node.childNodes[1].firstChild, 0);
|
2025-09-15 08:56:19 -03:00
|
|
|
|
testDelete("d", (node) => node.childNodes[3].firstChild, 0);
|
|
|
|
|
|
testDelete("e", (node) => node.childNodes[2].firstChild, 0);
|
|
|
|
|
|
testDelete("f", (node) => node.firstChild.firstChild.firstChild, 0, 3);
|
2024-11-30 08:20:44 -03:00
|
|
|
|
});
|
|
|
|
|
|
</script>
|