mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 10:07:15 +02:00
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.
This commit is contained in:
committed by
Tim Flynn
parent
f77f169824
commit
b9da7baac4
Notes:
github-actions[bot]
2025-09-16 10:58:28 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/b9da7baac41 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6203 Reviewed-by: https://github.com/trflynn89 ✅
@@ -3,16 +3,19 @@
|
||||
<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, position) {
|
||||
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, position, anchor, position);
|
||||
getSelection().setBaseAndExtent(anchor, start, anchor, end);
|
||||
|
||||
// Press backspace
|
||||
document.execCommand("delete");
|
||||
@@ -23,5 +26,8 @@
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user