Live Selection API
Inspect the current selection
Select text in the document. The range and character attributes below follow the selection automatically.
Start0zero-based
Length0characters
End0start + length
0+0=0
Selected text
Loading selection...
Waiting for the editor
Ready to tryUse the controls above to interact with this demo.
What this demonstrates
Understand ranges and common formatting
A selection identifies a document range and exposes the character attributes shared by the text in that range. The same object can inspect, select and format content.
Selection object
TXTextControl.selection
Range members
Selection.getStart / getLength
Uniform format detection
Selection.isCommonSelectionValueSelected
How it works
Selection.getStart returns the zero-based position of the first selected character. Selection.getLength returns the number of selected characters, so the end position is calculated as start + length. A length of 0 represents the text input position rather than a range of characters.
The inspector listens for inputPositionChanged and charFormatChanged. It reads the selected text and character attributes through callback-based API calls whenever the range or its formatting changes.
Before displaying a formatting value, Selection.isCommonSelectionValueSelected checks whether every selected character shares that value. Mixed fonts, colors or styles are therefore reported as Mixed instead of presenting a misleading default.
NuGet packages
TXTextControl.TextControl.Core.SDK
34.0.4
Provides the core document model and server-side document processing APIs.
dotnet add package TXTextControl.TextControl.Core.SDK --version 34.0.4
Provides the browser-based TX Text Control document editor and JavaScript API.
dotnet add package TXTextControl.Web --version 34.4.0
TXTextControl.Web.DocumentEditor.Backend
34.4.0
Hosts the WebSocket-based backend used by the browser document editor.
dotnet add package TXTextControl.Web.DocumentEditor.Backend --version 34.4.0