Skip to content

LinkPathInputSuggest

Completes the WHOLE value of an input as a link path, for a field that holds only a link target, such as the target field of a link editor. It is the counterpart of LinkAndTagInputSuggest, which completes a [[ link typed inside free text.

Before a # it suggests vault files by their link text relative to the source path. After <path># it suggests the headings of the file that path resolves to, and after a bare # those of the source file. A block subpath (#^) gets no suggestions. Picking a suggestion replaces the value and dispatches an input event, so a component listening on the input sees the change.

The value is the link path as Obsidian resolves it, not URL-encoded: a caller that writes it into a Markdown link encodes it there.

new Setting(containerEl).addText((text) => {
new LinkPathInputSuggest({ app: this.app, inputEl: text.inputEl, sourcePath: file.path });
});

Import:

import { LinkPathInputSuggest } from '@mnaoumov/obsidian-lib/link-path-input-suggest';

Signature:

export class LinkPathInputSuggest extends AbstractInputSuggest<LinkPathSuggestion>

Extends: AbstractInputSuggest<LinkPathSuggestion>

Constructor

new LinkPathInputSuggest(params: LinkPathInputSuggestConstructorParams)

Creates the suggest and attaches it to the input.

Properties

PropertyTypeDescription
inputElHTMLInputElementThe input the suggest completes.
sourcePathstringThe path that link paths are resolved and made relative against.

Methods

MethodReturnsDescription
getHeadingSuggestions(value)LinkPathHeadingSuggestion[]Gets the heading suggestions for a value holding a #.
getSuggestions(value)LinkPathSuggestion[]Gets the suggestions for the whole value: files before a #, headings after it.
renderSuggestion(suggestion, el)voidRenders a suggestion.
resolveFile(linkpath)null | TFileResolves the path part of the value to a file.
selectSuggestion(suggestion, $event)voidReplaces the value with the picked link path, moves the caret to its end and dispatches an input event.

Links to this page: