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

@ -2657,6 +2657,15 @@ static Array const commands {
.preserves_overrides = true,
.mapped_value = "formatOutdent"_fly_string,
},
// AD-HOC: This is a Ladybird-specific formatting command that is not part of the spec. It has no action and as
// such, it's not supported in userland (yet). The relevant CSS property `white-space` is used to indicate
// that if this style value is found during editing commands, it is recorded and restored where necessary.
// This is used to keep things like <div style="white-space: pre">..</div> intact when a selection is
// deleted, for example.
CommandDefinition {
.command = CommandNames::preserveWhitespace,
.relevant_css_property = CSS::PropertyID::WhiteSpace,
},
// https://w3c.github.io/editing/docs/execCommand/#the-removeformat-command
CommandDefinition {
.command = CommandNames::removeFormat,