diff --git a/manifest.json b/manifest.json index 7b26d65..e77de52 100644 --- a/manifest.json +++ b/manifest.json @@ -5,5 +5,5 @@ "author": "lazyloong", "minAppVersion": "1.0.0", - "version": "2.27.12" + "version": "2.27.13" } diff --git a/src/utils/pinyin.ts b/src/utils/pinyin.ts index 0cc878a..560e1c6 100644 --- a/src/utils/pinyin.ts +++ b/src/utils/pinyin.ts @@ -35,15 +35,14 @@ export class Pinyin extends Array { return score; } match(query: string, item: T, smathCase = false): MatchData { - let range = this.match_(query, smathCase); - range = range ? toRanges(range) : false; + const range_ = this.match_(query, smathCase); + const range = range_ ? toRanges(range_) : false; if (!range) return; - let data: MatchData = { + return { item: item, score: this.getScore(range), range: range, }; - return data; } concat(pinyin: Pinyin) { let result = new Pinyin("", null); @@ -58,14 +57,19 @@ export class Pinyin extends Array { } // The following two functions are based on the work of zh-lx (https://github.com/zh-lx). // Original code: https://github.com/zh-lx/pinyin-pro/blob/main/lib/core/match/index.ts. - match_(pinyin: string, smathCase: boolean) { + match_(pinyin: string, smathCase: boolean): number[] | null { pinyin = pinyin.replace(/\s/g, ""); - let f = (str: string) => (smathCase ? str : str.toLocaleLowerCase()); - const result = this.matchAboveStart(f(this.text), f(pinyin)); + const f = (str: string) => (smathCase ? str : str.toLocaleLowerCase()); + let result: number[]; + try { + result = this.matchAboveStart(f(this.text), f(pinyin)); + } catch (e) { + console.log(this, pinyin); + } return result; } - matchAboveStart(text: string, pinyin: string) { + matchAboveStart(text: string, pinyin: string): number[] | null { const words = text.split(""); // 二维数组 dp[i][j],i 表示遍历到的 text 索引+1, j 表示遍历到的 pinyin 的索引+1