mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Implement the "subscript" editing command
This commit is contained in:
parent
8c51d6863f
commit
ef8af01e1d
Notes:
github-actions[bot]
2025-01-10 22:36:16 +00:00
Author: https://github.com/gmta
Commit: ef8af01e1d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3216
4 changed files with 100 additions and 0 deletions
34
Tests/LibWeb/Text/input/Editing/execCommand-subscript.html
Normal file
34
Tests/LibWeb/Text/input/Editing/execCommand-subscript.html
Normal file
|
@ -0,0 +1,34 @@
|
|||
<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>
|
Loading…
Add table
Add a link
Reference in a new issue