LinkAndTagInputSuggest
Completes [[ links and # tags inside any <input> or <textarea>.
Obsidian’s AbstractInputSuggest treats the whole value as the query and replaces it on selection. This one reads the trigger before the caret and replaces only that, so it works inside free text such as a template or a description setting, and it accepts a <textarea> too.
new Setting(containerEl).addTextArea((textArea) => { new LinkAndTagInputSuggest({ app: this.app, inputEl: textArea.inputEl });});Import:
import { LinkAndTagInputSuggest } from '@mnaoumov/obsidian-lib/link-and-tag-input-suggest';Signature:
export class LinkAndTagInputSuggest extends AbstractInputSuggest<LinkAndTagSuggestion>Extends: AbstractInputSuggest<LinkAndTagSuggestion>
Constructor
new LinkAndTagInputSuggest(params: LinkAndTagInputSuggestConstructorParams)Creates the suggest and attaches it to the element.
Properties
| Property | Type | Description |
|---|---|---|
| inputEl | HTMLInputElement | HTMLTextAreaElement | The element the suggest completes in. |
| shouldSuggestLinks | boolean | Whether [[ completes links. |
| shouldSuggestTags | boolean | Whether # completes tags. |
| sourcePath | string | The path that inserted links are relative to. |
Methods
| Method | Returns | Description |
|---|---|---|
| getLinkSuggestions(query) | LinkSuggestion[] | Gets the link suggestions for a query. |
| getSuggestions() | LinkAndTagSuggestion[] | Gets the suggestions for the trigger before the caret. The query Obsidian passes is the whole value, so it is ignored. |
| getTagSuggestions(query) | TagSuggestion[] | Gets the tag suggestions for a query, from the tags of every note. |
| getTrigger() | LinkAndTagCompletionTrigger | null | Gets the enabled trigger before the caret. |
| getValue() | string | Gets the value of the element. |
| renderSuggestion(suggestion, el) | void | Renders a suggestion. |
| selectSuggestion(suggestion, $event) | void | Inserts the suggestion in place of the trigger, moves the caret after it and dispatches an input event, so a component listening on the element sees the change. |
| setValue(value) | void | Sets the value of the element. |
Links to this page: