Source code

Revision control

Copy as Markdown

Other Tools

<!doctype html>
<head>
<meta charset="utf-8">
<script src="/tests/SimpleTest/EventUtils.js"></script>
</head>
<body>
<div></div>
<script>
'use strict';
const host = document.querySelector('div');
const textNode = document.createTextNode('');
const editContext = new EditContext();
host.append(textNode);
editContext.addEventListener('textupdate', () => {
textNode.data = editContext.text;
getSelection().setBaseAndExtent(textNode, editContext.selectionStart,
textNode, editContext.selectionEnd);
});
host.editContext = editContext;
function compositionUpdate(newString, attr) {
synthesizeCompositionChange({
composition: {
string: newString,
clauses: [
{length: newString.length, attr },
]
},
caret: {
start: newString.length,
length: 0,
},
key: {
key: 'a',
}
});
}
function compositionEnd() {
synthesizeComposition({
type: 'compositioncommitasis',
key: {
key: 'b'
}
});
}
onload = () => {
let formats = [];
editContext.addEventListener('textformatupdate', e => {
formats.push(...e.getTextFormats().map(f => `${f.underlineThickness} ${f.underlineStyle}`));
});
host.focus();
compositionUpdate('test', COMPOSITION_ATTR_SELECTED_CLAUSE);
compositionUpdate('test2', COMPOSITION_ATTR_RAW_CLAUSE);
compositionEnd();
parent.postMessage(formats);
};
</script>
</body>