obsidian#EditorSuggestContext TypeScript Examples

The following examples show how to use obsidian#EditorSuggestContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Autocomplete.ts    From Templater with GNU Affero General Public License v3.0 6 votes vote down vote up
getSuggestions(
        context: EditorSuggestContext
    ): Array<TpSuggestDocumentation> {
        let suggestions: Array<TpSuggestDocumentation>;
        if (this.module_name && this.function_trigger) {
            suggestions =
                this.documentation.get_all_functions_documentation(
                    this.module_name as ModuleName
                );
        } else {
            suggestions =
                this.documentation.get_all_modules_documentation();
        }
        if (!suggestions) {
            return [];
        }
        return suggestions.filter(s => s.name.startsWith(context.query));
    }
Example #2
Source File: date-suggest.ts    From nldates-obsidian with MIT License 6 votes vote down vote up
getSuggestions(context: EditorSuggestContext): IDateCompletion[] {
    const suggestions = this.getDateSuggestions(context);
    if (suggestions.length) {
      return suggestions;
    }

    // catch-all if there are no matches
    return [{ label: context.query }];
  }
Example #3
Source File: locationSuggest.ts    From obsidian-map-view with GNU General Public License v3.0 6 votes vote down vote up
async getSearchResultsWithDelay(
        context: EditorSuggestContext
    ): Promise<SuggestInfo[] | null> {
        const timestamp = Date.now();
        this.lastSearchTime = timestamp;
        const Sleep = (ms: number) =>
            new Promise((resolve) => setTimeout(resolve, ms));
        await Sleep(this.delayInMs);
        if (this.lastSearchTime != timestamp) {
            // Search is canceled by a newer search
            return null;
        }
        // After the sleep our search is still the last -- so the user stopped and we can go on
        const searchResults = await this.searcher.search(context.query);
        let suggestions: SuggestInfo[] = [];
        for (const result of searchResults)
            suggestions.push({
                ...result,
                context: context,
            });
        return suggestions;
    }
Example #4
Source File: tagSuggest.ts    From obsidian-map-view with GNU General Public License v3.0 6 votes vote down vote up
getSuggestions(context: EditorSuggestContext): SuggestInfo[] {
		const noPound = (tagName: string) => {
			return tagName.startsWith('#') ? tagName.substring(1) : tagName;
		};
        const tagQuery = context.query ?? '';
        // Find all tags that include the query
        const matchingTags = utils
            .getAllTagNames(this.app)
			.map(value => noPound(value))
            .filter((value) =>
                value.toLowerCase().includes(tagQuery.toLowerCase())
            );
        return matchingTags.map((tagName) => {
            return {
                tagName: tagName,
                context: context,
            };
        });
    }
Example #5
Source File: date-suggest.ts    From nldates-obsidian with MIT License 5 votes vote down vote up
getDateSuggestions(context: EditorSuggestContext): IDateCompletion[] {
    if (context.query.match(/^time/)) {
      return ["now", "+15 minutes", "+1 hour", "-15 minutes", "-1 hour"]
        .map((val) => ({ label: `time:${val}` }))
        .filter((item) => item.label.toLowerCase().startsWith(context.query));
    }
    if (context.query.match(/(next|last|this)/i)) {
      const reference = context.query.match(/(next|last|this)/i)[1];
      return [
        "week",
        "month",
        "year",
        "Sunday",
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
      ]
        .map((val) => ({ label: `${reference} ${val}` }))
        .filter((items) => items.label.toLowerCase().startsWith(context.query));
    }

    const relativeDate =
      context.query.match(/^in ([+-]?\d+)/i) || context.query.match(/^([+-]?\d+)/i);
    if (relativeDate) {
      const timeDelta = relativeDate[1];
      return [
        { label: `in ${timeDelta} minutes` },
        { label: `in ${timeDelta} hours` },
        { label: `in ${timeDelta} days` },
        { label: `in ${timeDelta} weeks` },
        { label: `in ${timeDelta} months` },
        { label: `${timeDelta} days ago` },
        { label: `${timeDelta} weeks ago` },
        { label: `${timeDelta} months ago` },
      ].filter((items) => items.label.toLowerCase().startsWith(context.query));
    }

    return [{ label: "Today" }, { label: "Yesterday" }, { label: "Tomorrow" }].filter(
      (items) => items.label.toLowerCase().startsWith(context.query)
    );
  }
Example #6
Source File: locationSuggest.ts    From obsidian-map-view with GNU General Public License v3.0 5 votes vote down vote up
context: EditorSuggestContext;
Example #7
Source File: locationSuggest.ts    From obsidian-map-view with GNU General Public License v3.0 5 votes vote down vote up
async getSuggestions(
        context: EditorSuggestContext
    ): Promise<SuggestInfo[]> {
        if (context.query.length < 2) return [];
        return await this.getSearchResultsWithDelay(context);
    }
Example #8
Source File: tagSuggest.ts    From obsidian-map-view with GNU General Public License v3.0 5 votes vote down vote up
context: EditorSuggestContext;
Example #9
Source File: main.ts    From obsidian-emoji-shortcodes with MIT License 5 votes vote down vote up
getSuggestions(context: EditorSuggestContext): string[] {
		let emoji_query = context.query.replace(':', '');
		return Object.keys(emoji).filter(p => p.includes(emoji_query));
	}
Example #10
Source File: suggest.ts    From obsidian-admonition with MIT License 5 votes vote down vote up
getSuggestions(ctx: EditorSuggestContext) {
        return Object.keys(this.plugin.admonitions).filter((p) =>
            p.toLowerCase().contains(ctx.query.toLowerCase())
        );
    }
Example #11
Source File: suggest.ts    From obsidian-admonition with MIT License 5 votes vote down vote up
getSuggestions(ctx: EditorSuggestContext) {
        return Object.keys(this.plugin.admonitions).filter((p) =>
            p.toLowerCase().contains(ctx.query.toLowerCase())
        );
    }