ladybird/Tests/LibWeb/Text/input/Editing/execCommand-forwardDelete.html

41 lines
1.7 KiB
HTML
Raw Permalink Normal View History

2025-03-18 15:28:35 -03:00
<!DOCTYPE html>
<meta charset="utf-8">
<script src="../include.js"></script>
<div id="a" contenteditable>foobar</div>
<div id="b" contenteditable>a&nbsp;&nbsp;&nbsp;</div>
<div id="c" contenteditable>a&nbsp;&nbsp;b</div>
<div id="d" contenteditable>a&nbsp;&nbsp;&nbsp;b</div>
<div id="e" contenteditable>a&nbsp;&nbsp;&nbsp;&nbsp;b</div>
<div id="f" contenteditable>a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b</div>
<div id="g" contenteditable>&nbsp;&nbsp;b</div>
<div id="h" contenteditable>foo👩🏼👨🏻bar</div>
<div id="i" contenteditable>foo<div>bar<br>baz</div></div>
<script>
test(() => {
const testForwardDelete = function(divId, anchorExpression, start, end = start) {
println(`--- ${divId} ---`);
const divElm = document.querySelector(`div#${divId}`);
println(`Before: ${divElm.innerHTML}`);
// Place cursor
const anchor = anchorExpression(divElm);
getSelection().setBaseAndExtent(anchor, start, anchor, end);
// Press delete
document.execCommand("forwardDelete");
println(`After: ${divElm.innerHTML}`);
};
testForwardDelete("a", (node) => node.firstChild, 3);
testForwardDelete("b", (node) => node.firstChild, 1);
testForwardDelete("c", (node) => node.firstChild, 1);
testForwardDelete("d", (node) => node.firstChild, 1);
testForwardDelete("e", (node) => node.firstChild, 1);
testForwardDelete("f", (node) => node.firstChild, 1);
testForwardDelete("g", (node) => node.firstChild, 0);
testForwardDelete("h", (node) => node.firstChild, 3);
testForwardDelete("i", (node) => node.firstChild, 3);
});
</script>