Skip to content

Commit

Permalink
try fix: #17
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyloong committed Nov 10, 2023
1 parent eb3a4db commit c045b70
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 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.8.0"
"version": "2.8.1"
}
24 changes: 14 additions & 10 deletions src/fuzzyFileModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export type Item = {
file: TFile;
type: "file" | "alias" | "heading";
name: string;
pinyin: Pinyin<Item>;
pinyin: Pinyin;
path: string;
pinyinOfPath: Pinyin<Item>;
pinyinOfPath: Pinyin;
};

export type MatchData = {
Expand Down Expand Up @@ -358,27 +358,31 @@ class PinyinIndex extends PI<Item> {

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;
}
}

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<any> = folderIndex.find((folder) => folder.name == file.parent.path)?.pinyin;
let fileNamePinyin = new Pinyin<Item>(name, plugin);
folderPathPinyin = new Pinyin<Item>("", plugin)
.concat(folderPathPinyin as any)
.concat(new Pinyin<Item>("/", 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,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/fuzzySuggestModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import FuzzyChinesePinyinPlugin from "./main";

export default class fuzzySuggestModal extends FuzzyModal<Item> {
index: any;
items: string[];
items: any[];
resolve: (value?: string) => void;
constructor(app: App, plugin: FuzzyChinesePinyinPlugin, text_items: string[], items: string[]) {
super(app, plugin);
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
async suggester(text_items: string[], items: any[]): Promise<string> {
let modal = new FuzzySuggestModal(app, this, text_items, items);
const promise: Promise<string> = new Promise((resolve: (value?: string) => void, reject) => modal.openAndGetValue(resolve, reject));
return await promise;
Expand Down
10 changes: 5 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type MatchData<T> = {

export type Item = {
name: string;
pinyin: Pinyin<Item>;
pinyin: Pinyin;
};

export class HistoryMatchDataNode<T> {
Expand Down Expand Up @@ -41,7 +41,7 @@ export class HistoryMatchDataNode<T> {
}
}

export class Pinyin<T extends Item> extends Array<PinyinChild> {
export class Pinyin extends Array<PinyinChild> {
text: string;
constructor(query: string, plugin: FuzzyChinesePinyinPlugin) {
super();
Expand All @@ -63,7 +63,7 @@ export class Pinyin<T extends Item> extends Array<PinyinChild> {
score += 30 / range.length; // 分割越少分越高
return score;
}
match(query: string, item: T, smathCase = false): MatchData<T> | false {
match<T extends Item>(query: string, item: T, smathCase = false): MatchData<T> | false {
let range = this.match_(query, smathCase);
range = range ? toRanges(range) : false;
if (!range) return false;
Expand All @@ -74,8 +74,8 @@ export class Pinyin<T extends Item> extends Array<PinyinChild> {
};
return data;
}
concat(pinyin: Pinyin<T>) {
let result = new Pinyin<T>("", null);
concat(pinyin: Pinyin) {
let result = new Pinyin("", null);
result.text = this.text + pinyin.text;
for (let i of this) {
result.push(i);
Expand Down

0 comments on commit c045b70

Please sign in to comment.