Text selection

Nutrient Web SDK comes with a reliable, cross-browser API to access text selection and retrieve both selected text and text lines located within a given selection range.

Subscribing to TextSelectionChange events

Text selection updates are dispatched every time a text is selected or deselected. Subscribing to the textSelection.change event ensures a notification when the selection changes:

instance.addEventListener("textSelection.change", textSelection => {
if (textSelection) {
textSelection.getText().then(text => {
console.log(text);
});
} else {
console.log("no text is selected");
}
});

Notice that when the text is deselected, the textSelection argument is null.