ladybird/Tests/LibWeb/Text/input/Editing/execCommand-selectAll.html
Jelle Raaijmakers d967f56936 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
2025-01-21 02:27:50 +00:00

49 lines
1.4 KiB
HTML

<script src="../include.js"></script>
<div contenteditable="true">
<span>foobar</span>
<ul>
<li>foo</li>
<li>bar</li>
<li>baz</li>
</ul>
</div>
<script>
test(() => {
const selection = getSelection();
const reportSelection = () => {
if (selection.rangeCount === 0) {
println('No range.');
return;
}
const range = selection.getRangeAt(0);
println(`${range.startContainer.nodeName} ${range.startOffset} - ${range.endContainer.nodeName} ${range.endOffset}`);
};
reportSelection();
let divElm = document.querySelector('div');
let range = document.createRange();
range.setStart(divElm, 0);
range.setEnd(divElm, 0);
selection.addRange(range);
reportSelection();
// Perform selectAll
document.execCommand('selectAll');
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>