generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate multi suggest to obsidian native
- Loading branch information
1 parent
e71dcf2
commit 6346b7a
Showing
7 changed files
with
358 additions
and
351 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.