Skip to content

Commit

Permalink
feat: 当单个拼音对应多个双拼时支持高亮提示所有匹配键位
Browse files Browse the repository at this point in the history
  • Loading branch information
hegotit committed Feb 17, 2024
1 parent bc0e11e commit 61ba9a7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/utils/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ declare global {
* ],
* zeroMap: [ // 零声母映射
* '${双拼按键}/${对应拼音}'
* ],
* additionalMap: [ // 附加映射
* '${双拼按键}/${对应拼音}'
* ],
* excludingMap: [ // 不匹配映射
* '${双拼按键}/${对应拼音}'
* ]
* }
* ```
*/
type RawShuangPinConfig = typeof configs["小鹤双拼"];
type RawShuangPinConfig = {
keyMap: string[],
zeroMap: string[],
additionalMap?: string[],
excludingMap?: string[],
};
type ShuangpinMode = ShuangpinConfig;
}

Expand All @@ -33,6 +44,7 @@ export class ShuangpinConfig {
zero2sp = new Map<string, string>(); // 双拼 -> 零声母
sp2py = new Map<string, string>(); // 双拼 -> 拼音
py2sp = new Map<string, string>(); // 拼音 -> 双拼
spNot2py = new Map<string, string>(); // 不匹配映射:双拼 -> 拼音

constructor(
public name: string,
Expand Down Expand Up @@ -60,6 +72,22 @@ export class ShuangpinConfig {
this.py2sp.set(zero, sp);
this.sp2py.set(sp, zero);
}
const additionalMap = config["additionalMap"];
if (additionalMap) {
for (const line of additionalMap) {
const [sp, pinyin] = line.split("/");
this.py2sp.set(pinyin, sp);
this.sp2py.set(sp, pinyin);
}
}

const excludingMap = config["excludingMap"];
if (excludingMap) {
for (const line of excludingMap) {
const [sp, pinyin] = line.split("/");
this.spNot2py.set(sp, pinyin);
}
}

const allCombs = product(
[...this.groupByKey.keys()],
Expand All @@ -72,8 +100,11 @@ export class ShuangpinConfig {
const pinyins = product(leads, follows);
for (const [l, f] of pinyins) {
const pinyin = l + f;
if (pinyin == this.spNot2py.get(sp)) {
continue;
}
if (validCombines.has(pinyin)) {
this.py2sp.set(pinyin, sp);
this.py2sp.set(pinyin, sp.concat(this.py2sp.get(pinyin) ?? ""));
this.sp2py.set(sp, pinyin);
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/utils/spconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,24 @@
"eu/er",
"eo/o",
"er/ou"
],
"additionalMap": [
"jw/jun",
"qw/qun",
"xw/xun",
"yw/yun",
"jj/juan",
"qj/quan",
"xj/xuan",
"yj/yuan",
"jx/jue",
"qx/que",
"xx/xue",
"yx/yue",
"jv/ju",
"qv/qu",
"xv/xu",
"yv/yu"
]
}
}

0 comments on commit 61ba9a7

Please sign in to comment.