diff --git a/manifest.json b/manifest.json index c28126d..ffaacaa 100644 --- a/manifest.json +++ b/manifest.json @@ -5,5 +5,5 @@ "author": "lazyloong", "minAppVersion": "1.0.0", - "version": "2.9.1" + "version": "2.10.1" } diff --git a/src/fuzzyFileModal.ts b/src/fuzzyFileModal.ts index 5041fe0..236b17f 100644 --- a/src/fuzzyFileModal.ts +++ b/src/fuzzyFileModal.ts @@ -149,7 +149,7 @@ export default class FuzzyFileModal extends FuzzyModal { node = node.next; if (_f) index++; } - let smathCase = /[A-Z]/.test(query), + let smathCase = /[A-Z]/.test(query) && this.plugin.settings.global.autoCaseSensitivity, indexNode = this.historyMatchData.index(index - 1), toMatchData = indexNode.itemIndex.length == 0 ? this.index.items : indexNode.itemIndex; for (let p of toMatchData) { @@ -160,7 +160,7 @@ export default class FuzzyFileModal extends FuzzyModal { if (this.plugin.settings.file.usePathToSearch && matchData1.length <= 10) { toMatchData = indexNode.itemIndexByPath.length == 0 ? this.index.items : indexNode.itemIndexByPath; for (let p of toMatchData.filter((p) => p.type == "file" && !matchData1.map((p) => p.item.path).includes(p.path))) { - let d = p.pinyinOfPath.match(query, p); + let d = p.pinyinOfPath.match(query, p, smathCase); if (d) { d.usePath = true; matchData2.push(d); @@ -316,18 +316,13 @@ class PinyinIndex extends PI { } } initEvent() { - this.registerEvent( - this.metadataCache.on("changed", (file, data, cache) => { - this.update("changed", file, { data, cache }); - }) - ); + this.registerEvent(this.metadataCache.on("changed", (file, data, cache) => this.update("changed", file, { data, cache }))); this.registerEvent(this.vault.on("rename", (file, oldPath) => this.update("rename", file, { oldPath }))); this.registerEvent(this.vault.on("create", (file) => this.update("create", file))); this.registerEvent(this.vault.on("delete", (file) => this.update("delete", file))); } - update(type: string, f: TAbstractFile, keys?: { oldPath?: string; data?: string; cache?: CachedMetadata }) { - if (!this.isEffectiveFile(f)) return; - let file = f as TFile; + update(type: string, file: TAbstractFile, keys?: { oldPath?: string; data?: string; cache?: CachedMetadata }) { + if (!this.isEffectiveFile(file)) return; switch (type) { case "changed": { this.items = this.items @@ -353,7 +348,7 @@ class PinyinIndex extends PI { } } - isEffectiveFile(file: TAbstractFile) { + isEffectiveFile(file: TAbstractFile): file is TFile { if (!(file instanceof TFile)) return false; if (this.plugin.settings.file.showAllFileTypes) return true; diff --git a/src/fuzzyModal.ts b/src/fuzzyModal.ts index e6dd3ec..b80e962 100644 --- a/src/fuzzyModal.ts +++ b/src/fuzzyModal.ts @@ -61,7 +61,7 @@ export default abstract class FuzzyModal extends SuggestModal { + text.setValue(this.plugin.settings.global.autoCaseSensitivity).onChange(async (value) => { + this.plugin.settings.global.autoCaseSensitivity = value; + await this.plugin.saveSettings(); + }); + }); containerEl.createEl("h2", { text: "文件搜索" }); new Setting(containerEl) .setName("显示附件") diff --git a/src/search.ts b/src/search.ts index 67bb56e..de04a36 100644 --- a/src/search.ts +++ b/src/search.ts @@ -6,14 +6,14 @@ export function fuzzyPinyinSearch(query: string, items: string[] | Item[], plugi if (isStringArray(items)) { items = stringArray2Items(items, plugin); } - return search(query, items); + return search(query, items, plugin.settings.global.autoCaseSensitivity); } function isStringArray(arr: string[] | Item[]): arr is string[] { return typeof arr[0] == "string"; } -function search(query: string, items: Item[]): MatchData[] { +function search(query: string, items: Item[], autoCaseSensitivity = true): MatchData[] { if (query == "") { return items.map((p) => ({ item: p, @@ -23,7 +23,7 @@ function search(query: string, items: Item[]): MatchData[] { } let matchData: MatchData[] = []; - let smathCase = /[A-Z]/.test(query); + let smathCase = /[A-Z]/.test(query) && autoCaseSensitivity; for (let p of items) { let d = p.pinyin.match(query, p, smathCase); if (d) matchData.push(d); diff --git a/src/tagEditorSuggest.ts b/src/tagEditorSuggest.ts index 805c3cd..d83b8ac 100644 --- a/src/tagEditorSuggest.ts +++ b/src/tagEditorSuggest.ts @@ -85,7 +85,7 @@ export default class TagEditorSuggest extends EditorSuggest> { node = node.next; if (_f) index++; } - let smathCase = /[A-Z]/.test(query), + let smathCase = /[A-Z]/.test(query) && this.plugin.settings.global.autoCaseSensitivity, indexNode = this.historyMatchData.index(index - 1), toMatchData = indexNode.itemIndex.length == 0 ? this.index.items : indexNode.itemIndex; for (let p of toMatchData) {