# Provider
Class
## About
`Suggestions.Provider` recognizes one application-defined text protocol and supplies choices for it. Add any number of providers to `Editor.SuggestionProviders`, which starts with a `Suggestions.EmojiProvider` for `:shortcode:` emoji. The editor does not assign meaning to trigger text, so providers may offer `@name`, `#topic`, `.Error`, `/command`, or other syntax.
Committed choices become semantic inline tags. Give each provider a stable `Identifier`; that identifier lets the editor find the same provider after JSON, HTML, or Markdown has been loaded.
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| Add | suggestion As GraffitiProEditor.Suggestions.Suggestion | (None) | Adds a text-triggered suggestion protocol choice. |
| Add | value As String <br> caption As String = "" | (None) | Adds a choice that shows caption in the popup, or value when caption is empty, and inserts the trigger followed by value, such as @ada. |
| CommitSuggestion | content As GraffitiProEditor.EditableContent <br> request As GraffitiProEditor.Suggestions.Request <br> suggestion As GraffitiProEditor.Suggestions.Suggestion <br> currentStyle As GraffitiProEditor.TextStyle | Integer | Applies the selected suggestion to editable content and returns the new caret position. |
| Constructor | identifier As String = "default" <br> trigger As String = "" | (None) | Creates a suggestion provider with a stable identifier. |
| IndexOf | suggestion As GraffitiProEditor.Suggestions.Suggestion | Integer | Returns the index of the supplied suggestion, or -1 when it is not found. |
| IndexOf | suggestion As String | Integer | Returns the index of the first suggestion with the supplied caption, or -1 when it is not found. |
| LastIndex | (None) | Integer | Returns the last valid index of the explicitly added suggestions, or -1 when the provider is empty. |
| Lookup | caption As String | GraffitiProEditor.Suggestions.Suggestion | Returns the first explicitly added suggestion with the supplied caption, or Nil when no match exists. |
| Match | textBeforeCaret As String <br> caretPosition As Integer <br> content As GraffitiProEditor.Suggestions.Content | GraffitiProEditor.Suggestions.Request | Returns a request when text immediately before the caret matches a suggestion protocol. |
| RemoveAll | (None) | (None) | Removes all suggestion protocols and choices from this provider. |
| RemoveAt | index As Integer | (None) | Removes the explicitly added suggestion at the supplied index. Invalid indexes are ignored. |
| Suggestions | request As GraffitiProEditor.Suggestions.Request <br> maximumResults As Integer = 6 | GraffitiProEditor.Suggestions.Suggestion | Returns suggestions for the supplied request. |
## Properties
| Name | Type | Default Value | Description |
| --- | :---: | :---: | --- |
| BackgroundColor | Color | &cDBEAFE | Gets or sets the default background color for committed tags. |
| BorderColor | Color | &c93C5FD | Gets or sets the default border color for committed tags. |
| Identifier | String | (None) | Gets or sets the stable provider identifier preserved with committed tags. |
| TextColor | Color | &c1E40AF | Gets or sets the default text color for committed tags. |
| Trigger | String | (None) | Gets or sets the text that starts lookups for this provider. |
## Notes
### Custom Providers
Subclass `Suggestions.Provider` and override `Match` to recognize custom syntax, `Suggestions` to query your own model or service, or `CommitSuggestion` to control insertion. Return custom `Suggestions.Suggestion` subclasses when a popup row also needs custom drawing.
Override `Suggestions` when choices come from a dynamic source. Keep slow network work outside editor callbacks so typing remains responsive: cache remote results, return the cached choices, and refresh the editor after the cache changes.
### Document Storage
Provider objects, requests, and available choices are runtime application objects. Assign providers after constructing an editor. A committed tag stores the provider identifier, suggestion identifier, and fallback colors with each character so it remains recognizable and readable when the provider is unavailable.
JSON stores these values in `TextStyle`. HTML and Markdown use a styled `span` with `data-gpe-suggestion-provider` and `data-gpe-suggestion-id` attributes. Loading that content reconstructs the semantic tag. Use stable provider identifiers across application launches.
## Examples
```xojo
Var suggestions As New GraffitiProEditor.Suggestions.Provider("people", "@")
suggestions.Add("ada", "Ada Lovelace")
suggestions.Add("grace", "Grace Hopper")
suggestions.TextColor = Color.RGB(30, 64, 175)
suggestions.BackgroundColor = Color.RGB(219, 234, 254)
suggestions.BorderColor = Color.RGB(147, 197, 253)
Editor.SuggestionProviders.Add(suggestions)
```
Set `Node.SuggestionProvider` when one editable node needs a different source. A node-level `Suggestions.Provider` takes priority over providers registered with the editor.
`Add(value, caption)` shows `caption` in the popup and inserts the trigger followed by `value`, so `suggestions.Add("ada", "Ada Lovelace")` lists "Ada Lovelace" and inserts "@ada". A value that already starts with the trigger is not doubled. `value` is also the choice's `Identifier` and the text a query is matched against.
Use `LastIndex`, `IndexOf`, `Lookup`, `RemoveAt`, and `RemoveAll` to manage choices added directly to a provider. String lookup compares captions without regard to letter case.
When a node is added or imported, the editor checks its plain trigger text against registered providers. An exact `InsertText` match is converted into a committed tag automatically, preserving the same provider identifier, suggestion identifier, and tag colors as an interactive selection. Text that does not exactly match a supplied suggestion remains ordinary text.