1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibWeb: Add new whitespace-preserving editing command

Major browsers seem to preserve `white-space: pre/pre-wrap` styles in a
`<div>` when deleting the current selection through an editing command.
The idiomatic way to support this is to have a command with a "relevant
CSS property" to make sure the value is recorded and restored where
appropriate, however, no such command exists.

Create a custom command (internal to Ladybird) that implements this
behavior.
This commit is contained in:
Jelle Raaijmakers 2025-05-16 15:22:34 +02:00 committed by Andreas Kling
parent 1c77b42a44
commit a1467c22d3
Notes: github-actions[bot] 2025-05-16 22:30:14 +00:00
6 changed files with 38 additions and 5 deletions

View file

@ -0,0 +1,2 @@
Before: foo<div style="white-space: pre">bar</div>
After: foo<span style="white-space: pre;">bar</span>

View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<div contenteditable>foo<div style="white-space: pre">bar</div></div>
<script>
test(() => {
var divElm = document.querySelector('div');
println(`Before: ${divElm.innerHTML}`);
// Put cursor before 'bar'
var range = document.createRange();
range.setStart(divElm.childNodes[1].childNodes[0], 0);
getSelection().addRange(range);
// Press backspace
document.execCommand('delete');
println(`After: ${divElm.innerHTML}`);
});
</script>