mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibWeb: Implement the "selectAll" editing command
This commit is contained in:
parent
03bcfb9b8c
commit
70af48c18b
Notes:
github-actions[bot]
2025-01-10 22:34:39 +00:00
Author: https://github.com/gmta
Commit: 70af48c18b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3216
4 changed files with 73 additions and 0 deletions
|
@ -2228,6 +2228,33 @@ bool command_remove_format_action(DOM::Document& document, String const&)
|
|||
return true;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-selectall-command
|
||||
bool command_select_all_action(DOM::Document& document, String const&)
|
||||
{
|
||||
// NOTE: The spec mentions "This is totally broken". So fair warning :^)
|
||||
|
||||
// 1. Let target be the body element of the context object.
|
||||
GC::Ptr<DOM::Node> target = document.body();
|
||||
|
||||
// 2. If target is null, let target be the context object's documentElement.
|
||||
if (!target)
|
||||
target = document.document_element();
|
||||
|
||||
// 3. If target is null, call getSelection() on the context object, and call removeAllRanges() on the result.
|
||||
auto& selection = *document.get_selection();
|
||||
if (!target) {
|
||||
selection.remove_all_ranges();
|
||||
}
|
||||
|
||||
// 4. Otherwise, call getSelection() on the context object, and call selectAllChildren(target) on the result.
|
||||
else {
|
||||
MUST(selection.select_all_children(*target));
|
||||
}
|
||||
|
||||
// 5. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-strikethrough-command
|
||||
bool command_strikethrough_action(DOM::Document& document, String const&)
|
||||
{
|
||||
|
@ -2602,6 +2629,11 @@ static Array const commands {
|
|||
.command = CommandNames::removeFormat,
|
||||
.action = command_remove_format_action,
|
||||
},
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-selectall-command
|
||||
CommandDefinition {
|
||||
.command = CommandNames::selectAll,
|
||||
.action = command_select_all_action,
|
||||
},
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-strikethrough-command
|
||||
CommandDefinition {
|
||||
.command = CommandNames::strikethrough,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue