# TextServiceProvider
Class
## About
Subclass `TextServiceProvider` to contribute a replaceable text-entry capability. A provider may initiate native character input, identify misspellings, suggest or apply corrections, learn or ignore words, and contribute state-aware native context-menu items.
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| BeginCharacterInput | session As TextServiceSession | Boolean | Begins character input for the supplied active text-service session and returns whether a picker was presented. |
| CheckWord | word As String <br> language As String = "" | Boolean | Returns whether the supplied word is accepted by the provider for the requested language. |
| Constructor | identifier As String <br> displayName As String | (None) | Creates a text-service provider with the supplied stable identifier and display name. |
| ContextMenuItems | session As TextServiceSession <br> placement As GraffitiProEditor.TextServices.MenuPlacements | DesktopMenuItem | Returns newly constructed native menu items for the supplied session and contextual-menu placement. |
| Correction | word As String <br> language As String = "" | String | Returns an automatic replacement for the supplied word, or an empty string when no correction should be made. |
| CorrectionEnabled | (None) | Boolean | Returns whether automatic correction is currently enabled for this provider. |
| HandleContextMenuItem | session As TextServiceSession <br> selectedItem As DesktopMenuItem | Boolean | Handles a native contextual-menu item previously constructed by this provider and returns whether it was consumed. |
| IgnoreWord | word As String | (None) | Adds the supplied word to the provider's ignored-word list for the active document session. |
| IsAvailable | language As String = "" | Boolean | Returns whether this text-service provider is available for the requested language. |
| LearnWord | word As String | (None) | Adds the supplied word to the provider's learned-word dictionary. |
| SessionEnded | session As TextServiceSession | (None) | Releases provider resources associated with a text-service session that is no longer active. |
| Suggestions | word As String <br> language As String = "" | String | Returns spelling suggestions for the supplied word and language. |
## Properties
| Name | Type | Default Value | Description |
| --- | :---: | :---: | --- |
| DisplayName | String | (None) | Gets or sets the user-visible name of this text-service provider. |
| Enabled | Boolean | True | Gets or sets whether this provider can be selected for its supported text-service capabilities. |
| Identifier | String | (None) | Gets or sets the stable identifier used to register and locate this text-service provider. |
## Notes
Providers receive a session describing the current editor and text state.
### Cleanup
`SessionEnded` is called when the editor finishes a text-service session. Release operating-system objects, event handlers, and temporary session data there. After this call, the provider must not assume that the node or editor still exists.
### Context Menus
`ContextMenuItems` receives the active `TextServiceSession` and requested placement. Construct only items relevant to that state, including correct enabled and checked states. `HandleContextMenuItem` receives the same session after selection and should return `True` only when it handled the item.
Use stable tags on menu items so the provider can distinguish its own commands. Submenus are supported through normal `DesktopMenuItem` children.
### Provider Independence
Character input, spelling, correction, suggestions, and menus are capabilities rather than one indivisible service. Keep unrelated platform integrations in separate providers so an application can replace one feature without losing the others.
Use `IsAvailable` to report platform or language support and `Enabled` to let applications disable a provider without removing it. A provider that is unavailable should return neutral results rather than raising an exception during ordinary editing.
### Spelling and Correction
Return spelling ranges relative to the supplied word or session text as required by the calling method. Respect the requested language when the service supports multiple dictionaries. `CorrectionEnabled` determines whether automatic correction is attempted while explicit suggestions may remain available.
## Examples
Register application providers through the editor-owned `TextServices` collection.
### Custom Dictionary Provider
A provider may implement only the capabilities it supplies. Unimplemented base methods safely decline their operation.
```xojo
Class ProjectWordsProvider Inherits GraffitiProEditor.TextServiceProvider
Sub Constructor()
Super.Constructor("project-words", "Project Words")
End Sub
Function CheckWord(word As String, language As String = "") As Boolean
#Pragma Unused language
Return word = "GraffitiProEditor" Or word = "Xojo"
End Function
End Class
```
```xojo
Editor.TextServices.Add(New ProjectWordsProvider)
```