mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 00:29:15 +00:00
LibWeb: Require existing Selection for .execCommand("selectAll")
Disable the command if no selection is available. This is a spec bug: https://github.com/w3c/editing/issues/475 Fixes #3325
This commit is contained in:
parent
96e074b38f
commit
d967f56936
Notes:
github-actions[bot]
2025-01-21 02:28:49 +00:00
Author: https://github.com/gmta
Commit: d967f56936
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3328
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 21 additions and 5 deletions
|
@ -112,17 +112,17 @@ bool Document::query_command_enabled(FlyString const& command)
|
||||||
if (command.is_one_of(
|
if (command.is_one_of(
|
||||||
Editing::CommandNames::defaultParagraphSeparator,
|
Editing::CommandNames::defaultParagraphSeparator,
|
||||||
Editing::CommandNames::redo,
|
Editing::CommandNames::redo,
|
||||||
Editing::CommandNames::selectAll,
|
|
||||||
Editing::CommandNames::styleWithCSS,
|
Editing::CommandNames::styleWithCSS,
|
||||||
Editing::CommandNames::undo,
|
Editing::CommandNames::undo,
|
||||||
Editing::CommandNames::useCSS))
|
Editing::CommandNames::useCSS))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// AD-HOC: selectAll requires a selection object to exist.
|
||||||
|
if (command == Editing::CommandNames::selectAll)
|
||||||
|
return get_selection();
|
||||||
|
|
||||||
// The other commands defined here are enabled if the active range is not null,
|
// The other commands defined here are enabled if the active range is not null,
|
||||||
auto selection = get_selection();
|
auto active_range = Editing::active_range(*this);
|
||||||
if (!selection)
|
|
||||||
return false;
|
|
||||||
auto active_range = selection->range();
|
|
||||||
if (!active_range)
|
if (!active_range)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
No range.
|
No range.
|
||||||
DIV 0 - DIV 0
|
DIV 0 - DIV 0
|
||||||
BODY 0 - BODY 5
|
BODY 0 - BODY 5
|
||||||
|
true
|
||||||
|
false
|
||||||
|
false
|
||||||
|
Did not crash!
|
||||||
|
|
|
@ -33,5 +33,17 @@
|
||||||
// Perform selectAll
|
// Perform selectAll
|
||||||
document.execCommand('selectAll');
|
document.execCommand('selectAll');
|
||||||
reportSelection();
|
reportSelection();
|
||||||
|
|
||||||
|
// Report whether command is enabled and make sure it does not crash
|
||||||
|
const documents = [
|
||||||
|
document,
|
||||||
|
new Document(),
|
||||||
|
document.implementation.createHTMLDocument(),
|
||||||
|
];
|
||||||
|
for (const doc of documents) {
|
||||||
|
println(doc.queryCommandEnabled('selectAll'));
|
||||||
|
doc.execCommand('selectAll');
|
||||||
|
}
|
||||||
|
println('Did not crash!');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue