Skip to content

EditorSuggest

Defined in: obsidian.d.ts:1367

T

new EditorSuggest<T>(app): EditorSuggest<T>

Defined in: obsidian.d.ts:1381

App

EditorSuggest<T>

PopoverSuggest.constructor

app: App

Defined in: obsidian.d.ts:3400

PopoverSuggest.app


context: null | EditorSuggestContext

Defined in: obsidian.d.ts:1374

Current suggestion context, containing the result of onTrigger. This will be null any time the EditorSuggest is not supposed to run.


isOpen: boolean

Defined in: src/obsidian/augmentations/PopoverSuggest.d.ts:24

Whether the suggestion popup is currently open and visible.

PopoverSuggest.isOpen


limit: number

Defined in: obsidian.d.ts:1379

Override this to use a different limit for suggestion items


scope: Scope

Defined in: obsidian.d.ts:3402

PopoverSuggest.scope


suggestEl: HTMLElement

Defined in: src/obsidian/augmentations/PopoverSuggest.d.ts:38

Suggestion container element.

PopoverSuggest.suggestEl


suggestions: SuggestionContainer<T>

Defined in: src/obsidian/augmentations/PopoverSuggest.d.ts:45

Handles selection and rendering of the suggestions.

PopoverSuggest.suggestions

close(): void

Defined in: obsidian.d.ts:3409

void

PopoverSuggest.close

close(): void

Defined in: src/obsidian/augmentations/PopoverSuggest.d.ts:52

Closes the popover.

void

PopoverSuggest.close


constructor__(app): this

Defined in: src/obsidian/augmentations/EditorSuggest.d.ts:32

Create a new EditorSuggest.

App

The app instance.

this

PopoverSuggest.constructor__


abstract getSuggestions(context): T[] | Promise<T[]>

Defined in: obsidian.d.ts:1402

Generate suggestion items based on this context. Can be async, but preferably sync. When generating async suggestions, you should pass the context along.

EditorSuggestContext

T[] | Promise<T[]>


getSuggestions__(context): T[] | Promise<T[]>

Defined in: src/obsidian/augmentations/EditorSuggest.d.ts:59

Generate suggestion items based on this context. Can be async, but preferably sync. When generating async suggestions, you should pass the context along.

EditorSuggestContext

The context of the suggestion.

T[] | Promise<T[]>

The suggestion items.

class MyEditorSuggest extends EditorSuggest<string> {
public override getSuggestions(context: EditorSuggestContext): string[] {
return ['Item 1', 'Item 2', 'Item 3'];
}
}
class MyEditorSuggest extends EditorSuggest<string> {
public override getSuggestions(context: EditorSuggestContext): Promise<string[]> {
return Promise.resolve(['Item 1', 'Item 2', 'Item 3']);
}
}

abstract onTrigger(cursor, editor, file): null | EditorSuggestTriggerInfo

Defined in: obsidian.d.ts:1396

Based on the editor line and cursor position, determine if this 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.

EditorPosition

Editor

null | TFile

null | EditorSuggestTriggerInfo


onTrigger__(cursor, editor, file): null | EditorSuggestTriggerInfo

Defined in: src/obsidian/augmentations/EditorSuggest.d.ts:88

Based on the editor line and cursor position, determine if this 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.

EditorPosition

The cursor position.

Editor

The editor instance.

The file instance.

null | TFile

null | EditorSuggestTriggerInfo

The trigger info or null if the suggestion is not supposed to be triggered.

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 ?? ''
};
}
}

open(): void

Defined in: obsidian.d.ts:3407

void

PopoverSuggest.open

open(): void

Defined in: src/obsidian/augmentations/PopoverSuggest.d.ts:69

Opens the popover.

void

PopoverSuggest.open


abstract renderSuggestion(value, el): void

Defined in: obsidian.d.ts:3415

Render the suggestion item into DOM.

T

HTMLElement

void

PopoverSuggest.renderSuggestion


renderSuggestion__(value, el): void

Defined in: src/obsidian/augmentations/PopoverSuggest.d.ts:88

Render the suggestion.

T

The value to render.

HTMLElement

The element to render the suggestion to.

void

class MyPopoverSuggest extends PopoverSuggest<string> {
public override renderSuggestion(value: string, el: HTMLElement): void {
el.createEl('strong', { text: value });
}
}

PopoverSuggest.renderSuggestion__


abstract selectSuggestion(value, evt): void

Defined in: obsidian.d.ts:3420

Called when the user makes a selection.

T

MouseEvent | KeyboardEvent

void

PopoverSuggest.selectSuggestion


selectSuggestion__(value, evt): void

Defined in: src/obsidian/augmentations/PopoverSuggest.d.ts:107

Select the suggestion.

T

The value to select.

The event that triggered the selection.

MouseEvent | KeyboardEvent

void

class MyPopoverSuggest extends PopoverSuggest<string> {
public override selectSuggestion(value: string, evt: MouseEvent | KeyboardEvent): void {
console.log(value);
}
}

PopoverSuggest.selectSuggestion__


setInstructions(instructions): void

Defined in: obsidian.d.ts:1385

Instruction[]

void

setInstructions(instructions): void

Defined in: src/obsidian/augmentations/EditorSuggest.d.ts:100

Set the instructions for the suggestion.

Instruction[]

The instructions for the suggestion.

void

suggest.setInstructions([{ command: '↑↓', purpose: 'Navigate' }]);

showSuggestions(results): void

Defined in: src/obsidian/augmentations/EditorSuggest.d.ts:107

Show suggestions.

SearchResult[]

void