LibWeb: Do not rely on the layout tree for collapsed line breaks

The editing command that relies the most on this, `insertLinebreak`,
did not perform a layout update after inserting a `<br>` which caused
this algorithm to always return false. But instead of actually building
the layout tree needlessly, we can check the DOM tree instead.
This commit is contained in:
Jelle Raaijmakers
2025-05-01 12:27:42 +02:00
committed by Alexander Kalenik
parent 71a4e18bf8
commit 295b78f7d3
Notes: github-actions[bot] 2025-05-01 12:45:22 +00:00
3 changed files with 17 additions and 9 deletions

View File

@@ -3,11 +3,13 @@
<div id="a" contenteditable>foobar</div>
<div id="b" contenteditable><p style="white-space: pre">foobar</p></div>
<div id="c" contenteditable><p style="white-space: pre">foobar</p></div>
<div id="d" contenteditable>foo</div>
<script>
test(() => {
let divA = document.querySelector('div#a');
let divB = document.querySelector('div#b');
let divC = document.querySelector('div#c');
let divD = document.querySelector('div#d');
document.body.offsetWidth // Force a layout
@@ -37,5 +39,14 @@
document.execCommand('insertLinebreak');
println(`After: "${divC.innerHTML}"`);
getSelection().empty();
// D: Insert linebreak after 'foo'
println(`Before: "${divD.innerHTML}"`);
var range = document.createRange();
range.setStart(divD.firstChild, 3);
getSelection().addRange(range);
document.execCommand('insertLinebreak');
println(`After: "${divD.innerHTML}"`);
getSelection().empty();
});
</script>