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

Class UserFieldSuggest

src/modals/taskModalSuggests.ts:138–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136}
137
138export class UserFieldSuggest extends AbstractInputSuggest<UserFieldSuggestion> {
139 private plugin: TaskNotesPlugin;
140 private input: HTMLInputElement;
141 private fieldConfig: UserMappedField;
142
143 constructor(
144 app: App,
145 inputEl: HTMLInputElement,
146 plugin: TaskNotesPlugin,
147 fieldConfig: UserMappedField
148 ) {
149 super(app, inputEl);
150 this.plugin = plugin;
151 this.input = inputEl;
152 this.fieldConfig = fieldConfig;
153 }
154
155 protected async getSuggestions(_: string): Promise<UserFieldSuggestion[]> {
156 const isListField = this.fieldConfig.type === "list";
157 let currentQuery = "";
158 let currentValues: string[] = [];
159
160 if (isListField) {
161 currentValues = this.input.value.split(",").map((value: string) => value.trim());
162 currentQuery = currentValues[currentValues.length - 1] || "";
163 } else {
164 currentQuery = this.input.value.trim();
165 }
166 if (!currentQuery) return [];
167
168 const wikiMatch = currentQuery.match(/\[\[([^\]]*)$/);
169 if (wikiMatch) {
170 const partial = wikiMatch[1] || "";
171 const { FileSuggestHelper } = await import("../suggest/FileSuggestHelper");
172 const list = await FileSuggestHelper.suggest(
173 this.plugin,
174 partial,
175 20,
176 this.fieldConfig.autosuggestFilter
177 );
178 return list.map((item) => ({
179 value: item.insertText,
180 display: item.displayText,
181 type: "user-field" as const,
182 fieldKey: this.fieldConfig.key,
183 toString() {
184 return this.value;
185 },
186 }));
187 }
188
189 const existingValues = await this.getExistingUserFieldValues(this.fieldConfig.key);
190 return existingValues
191 .filter((value) => value && typeof value === "string")
192 .filter(
193 (value) =>
194 value.toLowerCase().includes(currentQuery.toLowerCase()) &&
195 (!isListField || !currentValues.slice(0, -1).includes(value))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected