Trilium Frontend API
    Preparing search index...

    Class CompletionContext

    An instance of this is passed to completion source functions.

    Index

    Constructors

    • Create a new completion context. (Mostly useful for testing completion sources—in the editor, the extension will create these for you.)

      Parameters

      • state: EditorState

        The editor state that the completion happens in.

      • pos: number

        The position at which the completion is happening.

      • explicit: boolean

        Indicates whether completion was activated explicitly, or implicitly by typing. The usual way to respond to this is to only return completions when either there is part of a completable entity before the cursor, or explicit is true.

      • Optionalview: EditorView

        The editor view. May be undefined if the context was created in a situation where there is no such view available, such as in synchronous updates via CompletionResult.update or when called by test code.

      Returns CompletionContext

    Properties

    explicit: boolean

    Indicates whether completion was activated explicitly, or implicitly by typing. The usual way to respond to this is to only return completions when either there is part of a completable entity before the cursor, or explicit is true.

    pos: number

    The position at which the completion is happening.

    The editor state that the completion happens in.

    view?: EditorView

    The editor view. May be undefined if the context was created in a situation where there is no such view available, such as in synchronous updates via CompletionResult.update or when called by test code.

    Accessors

    • get aborted(): boolean

      Yields true when the query has been aborted. Can be useful in asynchronous queries to avoid doing work that will be ignored.

      Returns boolean

    Methods

    • Allows you to register abort handlers, which will be called when the query is aborted.

      By default, running queries will not be aborted for regular typing or backspacing, on the assumption that they are likely to return a result with a validFor field that allows the result to be used after all. Passing onDocChange: true will cause this query to be aborted for any document change.

      Parameters

      • type: "abort"
      • listener: () => void
      • Optionaloptions: { onDocChange: boolean }

      Returns void

    • Get the match of the given expression directly before the cursor.

      Parameters

      • expr: RegExp

      Returns { from: number; text: string; to: number }

    • Get the extent, content, and (if there is a token) type of the token before this.pos.

      Parameters

      • types: readonly string[]

      Returns { from: number; text: string; to: number; type: NodeType }