Skip to content

EditorSuggest<T>

Official

Represents a autocomplete suggestion in the editor

Import:

import { EditorSuggest } from 'obsidian';

Signature:

export class EditorSuggest<T> extends PopoverSuggest<T>

Extends: PopoverSuggest<T>

Constructor

new EditorSuggest(app: App)

Constructor.

To extract the constructor type, use ExtractConstructor<EditorSuggest>.

Properties

PropertyTypeDescription
appAppThe Obsidian app instance.
(Inherited from PopoverSuggest)
contextEditorSuggestContext | nullCurrent suggestion context, containing the result of onTrigger. This will be null any time the EditorSuggest is not supposed to run.
instructionsElHTMLElementThe element holding the keyboard-shortcut instructions.
isOpenbooleanWhether the suggestion popup is currently open and visible.
(Inherited from PopoverSuggest)
limitnumberOverride this to use a different limit for suggestion items.
scopeScopeThe scope for the keymaps.
(Inherited from PopoverSuggest)
suggestElHTMLDivElementSuggestion container element.
(Inherited from PopoverSuggest)
suggestInnerElHTMLElementThe inner element holding the rendered suggestions.
(Inherited from PopoverSuggest)
suggestionsSuggestModalChooser<T, this>Handles selection and rendering of the suggestions.
(Inherited from PopoverSuggest)
winnull | WindowThe window the suggestion popover is shown in, or null while closed.
(Inherited from PopoverSuggest)

Methods

MethodReturnsDescription
attachDom()voidAttaches the suggestion popover to the document with an open animation.
(Inherited from PopoverSuggest)
autoDestroy()voidAutomatically destroy the popover when its associated element is removed.
(Inherited from PopoverSuggest)
close()voidCloses the popover.
(Inherited from PopoverSuggest)
detachDom()voidDetaches the suggestion popover from the document.
(Inherited from PopoverSuggest)
getSuggestions(context)Promise<T[]> | T[]Generate suggestion items based on this context. Can be async, but preferably sync. When generating async suggestions, you should pass the context along.
onEscapeKey()voidHandle the escape key to close the popover.
(Inherited from PopoverSuggest)
onSelectedChange(value, evt?)voidCalled after every selection change, including the programmatic one that follows SuggestModalChooser.setSuggestions.
(Inherited from PopoverSuggest)
onTrigger(cursor, editor, file)EditorSuggestTriggerInfo | nullBased on the editor line and cursor position, determine if this obsidian#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.
open()voidOpens the popover.
(Inherited from PopoverSuggest)
renderSuggestion(value, el)voidRender the suggestion.
(Inherited from PopoverSuggest)
reposition(rect, textDirection?)voidReposition the popover relative to the given bounding rectangle.
(Inherited from PopoverSuggest)
selectSuggestion(value, evt)voidSelect the suggestion.
(Inherited from PopoverSuggest)
setAutoDestroy(el)voidSet the element that triggers automatic destruction of the popover when removed.
(Inherited from PopoverSuggest)
setInstructions(instructions)voidSet the instructions for the suggestion.
showSuggestions(results)voidDisplay the given values as suggestions, truncated to limit, or close the popover if there are none.
trigger(editor, file, force)booleanEvaluates the trigger at the cursor and updates the suggestion context.
updatePosition()voidRepositions the suggestion popover at the current trigger location.

Links to this page: