mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-03 23:52:08 +00:00
Disable the command if no selection is available. This is a spec bug: https://github.com/w3c/editing/issues/475 Fixes #3325
49 lines
1.4 KiB
HTML
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>
|