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

@ -360,10 +360,11 @@ WebIDL::ExceptionOr<bool> Document::query_command_supported(FlyString const& com
if (!is_html_document())
return WebIDL::InvalidStateError::create(realm(), "queryCommandSupported is only supported on HTML documents"_string);
// When the queryCommandSupported(command) method on the Document interface is invoked, the
// user agent must return true if command is supported and available within the current script
// on the current site, and false otherwise.
return Editing::find_command_definition(command).has_value();
// When the queryCommandSupported(command) method on the Document interface is invoked, the user agent must return
// true if command is supported and available within the current script on the current site, and false otherwise.
// AD-HOC: Supported commands should have an action defined. Currently, ::preserveWhitespace does not have one.
auto command_definition = Editing::find_command_definition(command);
return command_definition.has_value() && command_definition->action;
}
// https://w3c.github.io/editing/docs/execCommand/#querycommandvalue()