LibWeb: Implement the "selectAll" editing command

This commit is contained in:
Jelle Raaijmakers 2025-01-10 16:18:44 +01:00 committed by Andreas Kling
commit 70af48c18b
Notes: github-actions[bot] 2025-01-10 22:34:39 +00:00
4 changed files with 73 additions and 0 deletions

View file

@ -0,0 +1,3 @@
No range.
DIV 0 - DIV 0
BODY 0 - BODY 5

View file

@ -0,0 +1,37 @@
<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();
});
</script>