# TextServiceSession
Class
## About
`TextServiceSession` is an immutable view of the active text-entry context plus controlled methods for changing that context. It identifies the editor, active node, text, selection, caret, contextual word, language, typing style, and menu coordinates.
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| Constructor | editor As Editor <br> activeNode As Node <br> selectionStart As Integer <br> selectionLength As Integer <br> caretPosition As Integer <br> caretBounds As Rect <br> contextMenuX As Double <br> contextMenuY As Double <br> contextMenuTextIndex As Integer <br> contextMenuWord As String <br> contextMenuWordRange As TextRange <br> typingStyle As TextStyle <br> language As String | (None) | Creates a text-service session. The editor creates one for each text-entry session and passes it to providers; applications do not construct sessions. |
| InsertText | value As String | Boolean | Inserts text at the active selection using the session's typing style and returns whether the document changed. |
| Invalidate | (None) | (None) | Invalidates this session so providers can no longer use it to mutate editor content. |
| ReplaceRange | range As TextRange <br> value As String | Boolean | Replaces the supplied grapheme-aligned range and returns whether the editor accepted the mutation. |
| ReplaceSelection | value As String | Boolean | Replaces the active selection and returns whether the editor accepted the mutation. |
| SelectRange | range As TextRange | Boolean | Selects the supplied grapheme-aligned range and returns whether the editor accepted it. |
## Properties
| Name | Type | Default Value | Description |
| --- | :---: | :---: | --- |
| ActiveNode | Node | (None) | Returns the node whose editable content is represented by this text-service session. |
| CaretBounds | Rect | (None) | Returns the document-space bounds of the active text caret. |
| CaretPosition | Integer | (None) | Returns the text-storage position of the active caret. |
| CaretWindowBounds | Rect | (None) | Returns the host window coordinates of the active text caret, suitable for positioning a runtime native control. |
| ContextMenuTextIndex | Integer | (None) | Returns the text-storage index nearest the contextual-menu pointer location. |
| ContextMenuWord | String | (None) | Returns the word under the contextual-menu location or immediately preceding the insertion point. |
| ContextMenuWordRange | TextRange | (None) | Returns the grapheme-aligned range occupied by the contextual word. |
| ContextMenuX | Double | (None) | Returns the horizontal document coordinate at which the contextual menu was requested. |
| ContextMenuY | Double | (None) | Returns the vertical document coordinate at which the contextual menu was requested. |
| HostControl | DesktopUIControl | (None) | Returns the editor control participating in this session, the parent for any native control a provider adds to HostWindow. |
| HostWindow | DesktopWindow | (None) | Returns the window that hosts the editor participating in this session. |
| IsActive | Boolean | (None) | Returns whether this session still targets the editor's active editable node. |
| Language | String | (None) | Returns the preferred language identifier used by text-service providers. |
| Owner | GraffitiProEditor.Editor | (None) | Returns the editor that started this text-service session. |
| ReadOnly | Boolean | (None) | Returns whether this session permits document mutations. |
| SelectedText | String | (None) | Returns the currently selected editable text. |
| SelectionLength | Integer | (None) | Returns the number of selected text-storage units. |
| SelectionStart | Integer | (None) | Returns the zero-based beginning of the active text selection. |
| Text | String | (None) | Returns the complete editable text represented by this text-service session. |
| TypingStyle | TextStyle | (None) | Returns a copy of the character style used for text inserted through this session. |
## Notes
Apply edits through the session so editor state remains consistent.
### Safe Editing
Use `InsertText`, `ReplaceSelection`, `ReplaceRange`, and `SelectRange` instead of modifying the node directly. These methods preserve the editor's text indexing, undo history, selection notifications, scrolling, and rendering invalidation.
A session becomes invalid when editing ends or its state is superseded. Providers should verify validity before acting on delayed native callbacks and should not retain a session after `SessionEnded`.