Files
ladybird/Tests/LibWeb/Text/input/Editing/execCommand-delete.html
Jelle Raaijmakers b9da7baac4 LibWeb: Extend logic for extraneous line breaks in block elements
While editing, we need to consider whether removing a <br> has any
effect on layout to determine whether its extraneous. This new condition
finds most cases for extraneous <br>s inside block elements.
2025-09-16 06:57:30 -04:00

34 lines
1.4 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<script src="../include.js"></script>
<div id="a" contenteditable>foobar</div>
<div id="b" contenteditable>foo👩🏼👨🏻bar</div>
<div id="c" contenteditable>foo<div contenteditable>bar</div></div>
<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>
<script>
test(() => {
const testDelete = 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 backspace
document.execCommand("delete");
println(`After: ${divElm.innerHTML}`);
};
testDelete("a", (node) => node.firstChild, 3);
testDelete("b", (node) => node.firstChild, 15);
testDelete("c", (node) => node.childNodes[1].firstChild, 0);
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);
});
</script>