Skip to content

Commit

Permalink
feat(suggesters): DataviewSuggest is now async
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed May 9, 2024
1 parent 239a4d5 commit dae4a25
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/suggesters/suggestFromDataview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ import { createRegexFromInput } from "./createRegexFromInput";
* For now, we are not very strict with the checks and just throw errors
*/
export class DataviewSuggest extends AbstractInputSuggest<string> {
sandboxedQuery: SafeDataviewQuery
sandboxedQuery: SafeDataviewQuery;

constructor(
public inputEl: HTMLInputElement,
dvQuery: string,
public app: App,
) {
super(app, inputEl);
this.sandboxedQuery = sandboxedDvQuery(dvQuery)
this.sandboxedQuery = sandboxedDvQuery(dvQuery);
}

getSuggestions(inputStr: string): string[] {
const result = executeSandboxedDvQuery(this.sandboxedQuery, this.app)
if (!inputStr) { return result }
const regex = createRegexFromInput(inputStr)
return result.filter((r) => regex.test(r))
getSuggestions(inputStr: string): Promise<string[]> {
const result = executeSandboxedDvQuery(this.sandboxedQuery, this.app);
if (!inputStr) {
return result();
}
const regex = createRegexFromInput(inputStr);
return result().then((res) => res.filter((r) => regex.test(r)));
}

renderSuggestion(option: string, el: HTMLElement): void {
Expand Down

0 comments on commit dae4a25

Please sign in to comment.