mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-02 23:21:56 +00:00
34 lines
1.3 KiB
HTML
34 lines
1.3 KiB
HTML
<script src="../include.js"></script>
|
|
<div contenteditable="true">foobar</div>
|
|
<script>
|
|
test(() => {
|
|
const range = document.createRange();
|
|
getSelection().addRange(range);
|
|
|
|
const divElm = document.querySelector('div');
|
|
const printableSelection = () => {
|
|
let activeRange = getSelection().getRangeAt(0);
|
|
return `${activeRange.startContainer.nodeName} ${activeRange.startOffset} ${activeRange.endContainer.nodeName} ${activeRange.endOffset}`;
|
|
};
|
|
const report = () => println(`Div contents: "${divElm.innerHTML}" state: ${document.queryCommandState('subscript')} selection: ${printableSelection()}`);
|
|
report();
|
|
|
|
// Add subscript to 'bar'
|
|
range.setStart(divElm.childNodes[0], 3);
|
|
range.setEnd(divElm.childNodes[0], 6);
|
|
document.execCommand('subscript');
|
|
report();
|
|
|
|
// Add subscript to 'foo'
|
|
range.setStart(divElm.childNodes[0], 0);
|
|
range.setEnd(divElm.childNodes[0], 3);
|
|
document.execCommand('subscript');
|
|
report();
|
|
|
|
// Desubscriptify 'bar'
|
|
range.setStart(divElm.childNodes[0].childNodes[1], 0);
|
|
range.setEnd(divElm.childNodes[0].childNodes[1], 3);
|
|
document.execCommand('subscript');
|
|
report();
|
|
});
|
|
</script>
|