Skip to content

Commit 078fea8

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

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-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
}

0 commit comments

Comments
 (0)