Skip to content

Commit

Permalink
feat: 双链建议 tab 键补全
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyloong committed May 16, 2024
1 parent 6a452eb commit 1628107
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
20 changes: 20 additions & 0 deletions obsidian.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,24 @@ declare module "obsidian" {
interface Scope {
keys: any[];
}
interface SuggestModal<T> {
chooser: {
values: T[];
suggestions: HTMLElement;
selectedItem: number;
addMessage(emptyStateText: string): unknown;
setSuggestions(arg0: T[]): void;
setSelectedItem(index: number, e: KeyboardEvent): void;
};
}
interface EditorSuggest<T> {
suggestions: {
chooser: this;
containerEl: HTMLDivElement;
selectedItem: number;
suggestions: Array<HTMLDivElement>;
values: T[];
useSelectedItem(e: KeyboardEvent): boolean;
};
}
}
4 changes: 4 additions & 0 deletions src/editorSuggest/fileEditorSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export default class FileEditorSuggest extends EditorSuggest<MatchData> {
);
this.plugin = plugin;
this.index = this.plugin.fileModal.index;
this.scope.register([], "Tab", (e) => {
e.preventDefault();
this.suggestions.useSelectedItem(e);
});
let prompt = [
{
command: "输入 #",
Expand Down
8 changes: 0 additions & 8 deletions src/modal/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { HistoryMatchDataNode, PinyinIndex, MatchData, Item, SuggestionRenderer

export default abstract class FuzzyModal<T extends Item> extends SuggestModal<MatchData<T>> {
historyMatchData: HistoryMatchDataNode<T>;
chooser: {
setSuggestions(arg0: MatchData<T>[]): void;
addMessage(emptyStateText: string): unknown;
suggestions: HTMLElement;
values: MatchData<T>[];
selectedItem: number;
setSelectedItem(index: number, e: KeyboardEvent): void;
};
index: PinyinIndex<T>;
plugin: ThePlugin;
useInput: boolean;
Expand Down

0 comments on commit 1628107

Please sign in to comment.