Skip to content

Commit 61ba9a7

Browse files
committed
feat: 当单个拼音对应多个双拼时支持高亮提示所有匹配键位
1 parent bc0e11e commit 61ba9a7

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/utils/keyboard.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@ declare global {
1414
* ],
1515
* zeroMap: [ // 零声母映射
1616
* '${双拼按键}/${对应拼音}'
17+
* ],
18+
* additionalMap: [ // 附加映射
19+
* '${双拼按键}/${对应拼音}'
20+
* ],
21+
* excludingMap: [ // 不匹配映射
22+
* '${双拼按键}/${对应拼音}'
1723
* ]
1824
* }
1925
* ```
2026
*/
21-
type RawShuangPinConfig = typeof configs["小鹤双拼"];
27+
type RawShuangPinConfig = {
28+
keyMap: string[],
29+
zeroMap: string[],
30+
additionalMap?: string[],
31+
excludingMap?: string[],
32+
};
2233
type ShuangpinMode = ShuangpinConfig;
2334
}
2435

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

3749
constructor(
3850
public name: string,
@@ -60,6 +72,22 @@ export class ShuangpinConfig {
6072
this.py2sp.set(zero, sp);
6173
this.sp2py.set(sp, zero);
6274
}
75+
const additionalMap = config["additionalMap"];
76+
if (additionalMap) {
77+
for (const line of additionalMap) {
78+
const [sp, pinyin] = line.split("/");
79+
this.py2sp.set(pinyin, sp);
80+
this.sp2py.set(sp, pinyin);
81+
}
82+
}
83+
84+
const excludingMap = config["excludingMap"];
85+
if (excludingMap) {
86+
for (const line of excludingMap) {
87+
const [sp, pinyin] = line.split("/");
88+
this.spNot2py.set(sp, pinyin);
89+
}
90+
}
6391

6492
const allCombs = product(
6593
[...this.groupByKey.keys()],
@@ -72,8 +100,11 @@ export class ShuangpinConfig {
72100
const pinyins = product(leads, follows);
73101
for (const [l, f] of pinyins) {
74102
const pinyin = l + f;
103+
if (pinyin == this.spNot2py.get(sp)) {
104+
continue;
105+
}
75106
if (validCombines.has(pinyin)) {
76-
this.py2sp.set(pinyin, sp);
107+
this.py2sp.set(pinyin, sp.concat(this.py2sp.get(pinyin) ?? ""));
77108
this.sp2py.set(sp, pinyin);
78109
}
79110
}

src/utils/spconfig.json

+18
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,24 @@
489489
"eu/er",
490490
"eo/o",
491491
"er/ou"
492+
],
493+
"additionalMap": [
494+
"jw/jun",
495+
"qw/qun",
496+
"xw/xun",
497+
"yw/yun",
498+
"jj/juan",
499+
"qj/quan",
500+
"xj/xuan",
501+
"yj/yuan",
502+
"jx/jue",
503+
"qx/que",
504+
"xx/xue",
505+
"yx/yue",
506+
"jv/ju",
507+
"qv/qu",
508+
"xv/xu",
509+
"yv/yu"
492510
]
493511
}
494512
}

0 commit comments

Comments
 (0)