Skip to content

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

PropertyTypeDescription
inputElHTMLInputElement | HTMLTextAreaElementThe element the suggest completes in.
shouldSuggestLinksbooleanWhether [[ completes links.
shouldSuggestTagsbooleanWhether # completes tags.
sourcePathstringThe path that inserted links are relative to.

Methods

MethodReturnsDescription
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 | nullGets the enabled trigger before the caret.
getValue()stringGets the value of the element.
renderSuggestion(suggestion, el)voidRenders a suggestion.
selectSuggestion(suggestion, $event)voidInserts 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)voidSets the value of the element.

Links to this page: