Trilium Frontend API
    Preparing search index...

    Interface CompletionResult

    Interface for objects returned by completion sources.

    interface CompletionResult {
        commitCharacters?: readonly string[];
        filter?: boolean;
        from: number;
        getMatch?: (
            completion: Completion,
            matched?: readonly number[],
        ) => readonly number[];
        map?: (current: CompletionResult, changes: ChangeDesc) => CompletionResult;
        options: readonly Completion[];
        to?: number;
        update?: (
            current: CompletionResult,
            from: number,
            to: number,
            context: CompletionContext,
        ) => CompletionResult;
        validFor?:
            | RegExp
            | (
                (
                    text: string,
                    from: number,
                    to: number,
                    state: EditorState,
                ) => boolean
            );
    }
    Index

    Properties

    commitCharacters?: readonly string[]

    Set a default set of commit characters for all options in this result.

    filter?: boolean

    By default, the library filters and scores completions. Set filter to false to disable this, and cause your completions to all be included, in the order they were given. When there are other sources, unfiltered completions appear at the top of the list of completions. validFor must not be given when filter is false, because it only works when filtering.

    from: number

    The start of the range that is being completed.

    getMatch?: (
        completion: Completion,
        matched?: readonly number[],
    ) => readonly number[]

    When filter is set to false or a completion has a displayLabel, this may be provided to compute the ranges on the label that match the input. Should return an array of numbers where each pair of adjacent numbers provide the start and end of a range. The second argument, the match found by the library, is only passed when filter isn't false.

    map?: (current: CompletionResult, changes: ChangeDesc) => CompletionResult

    When results contain position-dependent information in, for example, apply methods, you can provide this method to update the result for transactions that happen after the query. It is not necessary to update from and to—those are tracked automatically.

    options: readonly Completion[]

    The completions returned. These don't have to be compared with the input by the source—the autocompletion system will do its own matching (against the text between from and to) and sorting.

    to?: number

    The end of the range that is being completed. Defaults to the main cursor position.

    update?: (
        current: CompletionResult,
        from: number,
        to: number,
        context: CompletionContext,
    ) => CompletionResult

    Synchronously update the completion result after typing or deletion. If given, this should not do any expensive work, since it will be called during editor state updates. The function should make sure (similar to validFor) that the completion still applies in the new state.

    validFor?:
        | RegExp
        | ((text: string, from: number, to: number, state: EditorState) => boolean)

    When given, further typing or deletion that causes the part of the document between (mapped) from and to to match this regular expression or predicate function will not query the completion source again, but continue with this list of options. This can help a lot with responsiveness, since it allows the completion list to be updated synchronously.