2025-03-18 15:28:35 -03:00
|
|
|
<!DOCTYPE html>
|
2026-05-18 08:35:08 -03:00
|
|
|
<meta charset="utf-8">
|
2025-01-10 09:28:32 -03:00
|
|
|
<script src="../include.js"></script>
|
|
|
|
|
<div contenteditable="true">foobar</div>
|
|
|
|
|
<script>
|
|
|
|
|
test(() => {
|
2025-07-23 06:43:21 -03:00
|
|
|
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}`);
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-10 09:28:32 -03:00
|
|
|
var divElm = document.querySelector('div');
|
2025-01-23 06:50:00 -03:00
|
|
|
divElm.addEventListener('input', (e) => println('input triggered'));
|
2025-01-10 09:28:32 -03:00
|
|
|
|
|
|
|
|
// Put cursor between 'foo' and 'bar'
|
2025-07-23 06:43:21 -03:00
|
|
|
selection.setBaseAndExtent(divElm.childNodes[0], 3, divElm.childNodes[0], 3);
|
2025-01-10 09:28:32 -03:00
|
|
|
|
|
|
|
|
// Insert text
|
|
|
|
|
document.execCommand('insertText', false, 'baz');
|
2025-07-23 06:43:21 -03:00
|
|
|
reportSelection();
|
|
|
|
|
|
|
|
|
|
// Insert Unicode
|
|
|
|
|
document.execCommand('insertText', false, '🙂');
|
|
|
|
|
reportSelection();
|
2025-01-10 09:28:32 -03:00
|
|
|
|
|
|
|
|
println(divElm.innerHTML);
|
|
|
|
|
});
|
|
|
|
|
</script>
|