EditorSuggest.onTrigger method
EditorSuggest › onTrigger
Official
Based on the editor line and cursor position, determine if thisobsidian#EditorSuggest should be triggered at this moment. Typically, you would run a regular expression on the current line text before the cursor. Return null to indicate that this editor suggest is not supposed to be triggered.Please be mindful of performance when implementing this function, as it will be triggered very often (on each keypress). Keep it simple, and return
null as early as possible if you determine that it is not the right time. Signature:
onTrigger(cursor: EditorPosition, editor: Editor, file: TFile | null): EditorSuggestTriggerInfo | nullParameters:
| Parameter | Type | Description |
|---|---|---|
| cursor | EditorPosition | The cursor position. |
| editor | Editor | The editor instance. |
| file | TFile | null | The file instance. |
Returns: EditorSuggestTriggerInfo | null — The trigger info or null if the suggestion is not supposed to be triggered.
Since: 1.1.13
Example:
class MyEditorSuggest extends EditorSuggest<string> { public override onTrigger(cursor: EditorPosition, editor: Editor, file: TFile | null): EditorSuggestTriggerInfo | null { return { start: cursor, end: cursor, query: file?.basename ?? '' }; }}