Skip to content

Commit

Permalink
refactor: migrate multi suggest to obsidian native
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Oct 16, 2023
1 parent e71dcf2 commit 6346b7a
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 351 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"esbuild-svelte": "^0.8.0",
"obsidian": "latest",
"obsidian": "^1.4.11",
"svelte": "^4.2.0",
"svelte-preprocess": "^5.0.4",
"tslib": "2.4.0",
Expand Down
1 change: 1 addition & 0 deletions src/FormModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class FormModal extends Modal {
selectedVales: this.formResult[definition.name] as string[],
availableOptions: options,
setting: fieldBase,
app: this.app,
}
}))
return;
Expand Down
46 changes: 23 additions & 23 deletions src/suggesters/MultiSuggest.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { TextInputSuggest } from "./suggest";
import { AbstractInputSuggest, App } from 'obsidian'

export class MultiSuggest extends TextInputSuggest<string> {
content: Set<string>;
export class MultiSuggest extends AbstractInputSuggest<string> {
content: Set<string>;

constructor(input: HTMLInputElement, content: Set<string>, private onSelect: (value: string) => void) {
super(app, input);
this.content = content;
}
constructor(private inputEl: HTMLInputElement, content: Set<string>, private onSelectCb: (value: string) => void, app: App) {
super(app, inputEl);
this.content = content;
}

getSuggestions(inputStr: string): string[] {
const lowerCaseInputStr = inputStr.toLocaleLowerCase();
return [...this.content].filter((content) =>
content.toLocaleLowerCase().contains(lowerCaseInputStr)
);
}
getSuggestions(inputStr: string): string[] {
const lowerCaseInputStr = inputStr.toLocaleLowerCase();
return [...this.content].filter((content) =>
content.toLocaleLowerCase().contains(lowerCaseInputStr)
);
}

renderSuggestion(content: string, el: HTMLElement): void {
el.setText(content);
}
renderSuggestion(content: string, el: HTMLElement): void {
el.setText(content);
}

selectSuggestion(content: string): void {
this.onSelect(content);
this.inputEl.value = "";
// this.inputEl.trigger("blur");
this.inputEl.blur()
this.close();
}
selectSuggestion(content: string, evt: MouseEvent | KeyboardEvent): void {
this.onSelectCb(content);
this.inputEl.value = "";
// this.inputEl.trigger("blur");
this.inputEl.blur()
this.close();
}
}
Loading

0 comments on commit 6346b7a

Please sign in to comment.