mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 18:17:22 +02:00
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:
committed by
Alexander Kalenik
parent
71a4e18bf8
commit
295b78f7d3
Notes:
github-actions[bot]
2025-05-01 12:45:22 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/295b78f7d3b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4542
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user