diff --git a/manifest.json b/manifest.json index ec92d90..499329e 100644 --- a/manifest.json +++ b/manifest.json @@ -5,5 +5,5 @@ "author": "lazyloong", "minAppVersion": "1.0.0", - "version": "2.8.0" + "version": "2.8.1" } diff --git a/src/fuzzyFileModal.ts b/src/fuzzyFileModal.ts index 2b2096b..5041fe0 100644 --- a/src/fuzzyFileModal.ts +++ b/src/fuzzyFileModal.ts @@ -9,9 +9,9 @@ export type Item = { file: TFile; type: "file" | "alias" | "heading"; name: string; - pinyin: Pinyin; + pinyin: Pinyin; path: string; - pinyinOfPath: Pinyin; + pinyinOfPath: Pinyin; }; export type MatchData = { @@ -358,7 +358,8 @@ class PinyinIndex extends PI { if (this.plugin.settings.file.showAllFileTypes) return true; else if (DOCUMENT_EXTENSIONS.includes(file.extension)) return true; - else if (this.plugin.settings.file.showAttachments && this.plugin.settings.file.attachmentExtensions.includes(file.extension)) return true; + else if (this.plugin.settings.file.showAttachments && this.plugin.settings.file.attachmentExtensions.includes(file.extension)) + return true; else return false; } } @@ -366,19 +367,22 @@ class PinyinIndex extends PI { function TFile2Item(file: TFile, plugin: FuzzyChinesePinyinPlugin): Item { let name = file.extension != "md" ? file.name : file.basename; let folderIndex = plugin.folderModal.index.items; - let folderPathPinyin: Pinyin = folderIndex.find((folder) => folder.name == file.parent.path)?.pinyin; - let fileNamePinyin = new Pinyin(name, plugin); - folderPathPinyin = new Pinyin("", plugin) - .concat(folderPathPinyin as any) - .concat(new Pinyin("/", plugin)) - .concat(fileNamePinyin); + let fileNamePinyin = new Pinyin(name, plugin); + let folderPathPinyin: Pinyin; + let pathPinyin: Pinyin; + if (file.parent.path == "/") { + pathPinyin = fileNamePinyin; + } else { + folderPathPinyin = folderIndex.find((folder) => folder.name == file.parent.path).pinyin; + pathPinyin = folderPathPinyin.concat(new Pinyin("/", plugin)).concat(fileNamePinyin); + } return { type: "file", file: file, name: name, pinyin: fileNamePinyin, path: file.path, - pinyinOfPath: folderPathPinyin, + pinyinOfPath: pathPinyin, }; } diff --git a/src/fuzzySuggestModal.ts b/src/fuzzySuggestModal.ts index bb5c81f..52e9116 100644 --- a/src/fuzzySuggestModal.ts +++ b/src/fuzzySuggestModal.ts @@ -5,7 +5,7 @@ import FuzzyChinesePinyinPlugin from "./main"; export default class fuzzySuggestModal extends FuzzyModal { index: any; - items: string[]; + items: any[]; resolve: (value?: string) => void; constructor(app: App, plugin: FuzzyChinesePinyinPlugin, text_items: string[], items: string[]) { super(app, plugin); diff --git a/src/main.ts b/src/main.ts index 7b11a60..2c86eef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -195,7 +195,7 @@ export default class FuzzyChinesePinyinPlugin extends Plugin { async saveSettings() { await this.saveData(this.settings); } - async suggester(text_items: string[], items: string[]): Promise { + async suggester(text_items: string[], items: any[]): Promise { let modal = new FuzzySuggestModal(app, this, text_items, items); const promise: Promise = new Promise((resolve: (value?: string) => void, reject) => modal.openAndGetValue(resolve, reject)); return await promise; diff --git a/src/utils.ts b/src/utils.ts index 7998a68..7d92e76 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,7 +9,7 @@ export type MatchData = { export type Item = { name: string; - pinyin: Pinyin; + pinyin: Pinyin; }; export class HistoryMatchDataNode { @@ -41,7 +41,7 @@ export class HistoryMatchDataNode { } } -export class Pinyin extends Array { +export class Pinyin extends Array { text: string; constructor(query: string, plugin: FuzzyChinesePinyinPlugin) { super(); @@ -63,7 +63,7 @@ export class Pinyin extends Array { score += 30 / range.length; // 分割越少分越高 return score; } - match(query: string, item: T, smathCase = false): MatchData | false { + match(query: string, item: T, smathCase = false): MatchData | false { let range = this.match_(query, smathCase); range = range ? toRanges(range) : false; if (!range) return false; @@ -74,8 +74,8 @@ export class Pinyin extends Array { }; return data; } - concat(pinyin: Pinyin) { - let result = new Pinyin("", null); + concat(pinyin: Pinyin) { + let result = new Pinyin("", null); result.text = this.text + pinyin.text; for (let i of this) { result.push(i);