Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The EditContext() constructor returns a new EditContext object.
new EditContext()
new EditContext(options)options OptionalAn optional object with the following properties:
textA string to set the initial text of the EditContext.
selectionStartA number to set the initial selection start of the EditContext.
selectionEndA number to set the initial selection end of the EditContext.
EditContext objectThe following example creates a new EditContext object with the initial text "Hello world!" and the initial selection covering the entire text.
<div id="editor"></div>const initialText = "Hello world!";
const editContext = new EditContext({
text: initialText,
selectionStart: 0,
selectionEnd: initialText.length,
});
const editorElement = document.getElementById("editor");
editorElement.editContext = editContext;
console.log(
`EditContext object ready. Text: ${editContext.text}. Selection: ${editContext.selectionStart} - ${editContext.selectionEnd}.`,
);EditContext interface it belongs to.