MCPcopy
hub / github.com/callumalpass/tasknotes / ContextSuggest

Class ContextSuggest

src/modals/taskModalSuggests.ts:24–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24export class ContextSuggest extends AbstractInputSuggest<ContextSuggestion> {
25 private plugin: TaskNotesPlugin;
26 private input: HTMLInputElement;
27
28 constructor(app: App, inputEl: HTMLInputElement, plugin: TaskNotesPlugin) {
29 super(app, inputEl);
30 this.plugin = plugin;
31 this.input = inputEl;
32 openSuggestionsOnFieldSelection(this.input, () => this.open());
33 }
34
35 protected async getSuggestions(_: string): Promise<ContextSuggestion[]> {
36 const currentValues = this.input.value.split(",").map((value: string) => value.trim());
37 const currentQuery = currentValues[currentValues.length - 1];
38
39 const contexts = this.plugin.cacheManager.getAllContexts();
40 const alreadySelected = currentValues.slice(0, -1);
41 return contexts
42 .filter((context) => context && typeof context === "string")
43 .filter(
44 (context) =>
45 !alreadySelected.includes(context) &&
46 (!currentQuery || context.toLowerCase().includes(currentQuery.toLowerCase()))
47 )
48 .slice(0, 10)
49 .map((context) => ({
50 value: context,
51 display: context,
52 type: "context" as const,
53 toString() {
54 return this.value;
55 },
56 }));
57 }
58
59 public renderSuggestion(contextSuggestion: ContextSuggestion, el: HTMLElement): void {
60 el.textContent = contextSuggestion.display;
61 }
62
63 public selectSuggestion(contextSuggestion: ContextSuggestion): void {
64 const currentValues = this.input.value.split(",").map((value: string) => value.trim());
65 currentValues[currentValues.length - 1] = contextSuggestion.value;
66 this.input.value = currentValues.join(", ") + ", ";
67 this.input.dispatchEvent(new Event("input", { bubbles: true }));
68 this.input.focus();
69 }
70}
71
72interface TagSuggestion {
73 value: string;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected