mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
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.
40 lines
1.7 KiB
HTML
40 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
||
<script src="../include.js"></script>
|
||
<div id="a" contenteditable>foobar</div>
|
||
<div id="b" contenteditable>a </div>
|
||
<div id="c" contenteditable>a b</div>
|
||
<div id="d" contenteditable>a b</div>
|
||
<div id="e" contenteditable>a b</div>
|
||
<div id="f" contenteditable>a b</div>
|
||
<div id="g" contenteditable> 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>
|