Skip to content

Commit

Permalink
feat: 快捷选择历史文件 #47
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyloong committed Apr 28, 2024
1 parent 72d2ab1 commit d905d82
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"author": "lazyloong",

"minAppVersion": "1.0.0",
"version": "2.21.0"
"version": "2.22.0"
}
19 changes: 17 additions & 2 deletions src/modal/fileModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "@/utils";
import FuzzyChinesePinyinPlugin from "@/main";
import FuzzyModal from "./modal";
import { max, min } from "lodash";

const DOCUMENT_EXTENSIONS = ["md", "canvas"];

Expand Down Expand Up @@ -168,8 +169,22 @@ export default class FuzzyFileModal extends FuzzyModal<Item> {
}
}
getSuggestions(query: string): MatchData[] {
if (query == "") {
return this.getEmptyInputSuggestions();
if (query == "") return this.getEmptyInputSuggestions();
if (query[0] == " " && this.plugin.settings.file.quicklySelectHistoryFiles) {
let items = this.getEmptyInputSuggestions();
this.selectSuggestion;
switch (query.length) {
case 1:
return items;
case 2:
let index = max([
"asdfghjkl;".indexOf(query[1]),
"1234567890".indexOf(query[1]),
]);
index = min([index, items.length - 1]);
if (index == -1) break;
this.selectSuggestion(items[index], new MouseEvent("click"));
}
}

let matchData: MatchData[] = [],
Expand Down
13 changes: 13 additions & 0 deletions src/settingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ export default class SettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);
new Setting(this.containerEl)
.setName("快速选择历史文件")
.setDesc("输入栏为空时,空格加 asdfgh... 或 12345... 快速选择历史文件")
.addToggle((cb) => {
cb.setValue(this.plugin.settings.file.quicklySelectHistoryFiles).onChange(
async (value) => {
this.plugin.settings.file.quicklySelectHistoryFiles = value;
await this.plugin.saveSettings();
}
);
});
new Setting(this.containerEl)
.setName("附件后缀")
.setDesc("只显示这些后缀的附件")
Expand Down Expand Up @@ -333,6 +344,7 @@ export interface FuzyyChinesePinyinSettings {
showPath: boolean;
showTags: boolean;
searchWithTag: boolean;
quicklySelectHistoryFiles: boolean;
keyEnter: keyof typeof openFileKeyMap;
keyCtrlEnter: keyof typeof openFileKeyMap;
keyAltEnter: keyof typeof openFileKeyMap;
Expand Down Expand Up @@ -362,6 +374,7 @@ export const DEFAULT_SETTINGS: FuzyyChinesePinyinSettings = {
showAttachments: false,
showAllFileTypes: false,
showUnresolvedLink: false,
quicklySelectHistoryFiles: false,
attachmentExtensions: [
"bmp",
"png",
Expand Down

0 comments on commit d905d82

Please sign in to comment.