Skip to content

Commit ca2900c

Browse files
committed
🐛 修复mac下一些快捷键在中文状态时无法使用的问题
1 parent ce4a573 commit ca2900c

File tree

2 files changed

+119
-1799
lines changed

2 files changed

+119
-1799
lines changed

app/src/core/service/controlService/shortcutKeysEngine/KeyBinds.tsx

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Store } from "@tauri-apps/plugin-store";
22
import { createStore } from "../../../../utils/store";
33
import { Vector } from "../../../dataStruct/Vector";
4+
import { isMac } from "../../../../utils/platform";
45

56
/**
67
* 用于管理快捷键绑定
@@ -45,10 +46,22 @@ export namespace KeyBinds {
4546
return data || null;
4647
}
4748

49+
/**
50+
* 一个记录全部快捷键绑定对象的类
51+
* @param id 快捷键的英文字段名
52+
* @param key 按下的字母
53+
* @param modifiers 配合字母的修饰键
54+
*/
4855
const callbacks: {
4956
[key: string]: Array<(key: string, modifiers: KeyModifiers) => void>;
5057
} = {};
5158

59+
/**
60+
* 让某一个快捷键开始监听
61+
* @param id
62+
* @param callback
63+
* @returns
64+
*/
5265
export async function watch(id: string, callback: (key: string, modifiers: KeyModifiers) => void) {
5366
if (!store) {
5467
throw new Error("Store not initialized.");
@@ -154,6 +167,7 @@ export namespace KeyBinds {
154167
* @returns
155168
*/
156169
private matches(event: KeyboardEvent | MouseEvent | WheelEvent): boolean {
170+
// 先检查 修饰键 是否匹配
157171
let matchModifiers =
158172
this.modifiers.control === event.ctrlKey &&
159173
this.modifiers.alt === event.altKey &&
@@ -166,7 +180,38 @@ export namespace KeyBinds {
166180
matchModifiers = matchModifiers && !event.metaKey;
167181
}
168182

169-
const matchKey = event instanceof KeyboardEvent && event.key.toLowerCase() === this.key.toLowerCase();
183+
// 再检查 按键 是否匹配
184+
let matchKey = event instanceof KeyboardEvent && event.key.toLowerCase() === this.key.toLowerCase();
185+
// 处理macbook特殊中文按键符号问题
186+
if (isMac && event instanceof KeyboardEvent) {
187+
const currentKey = event.key.toLowerCase();
188+
const transedKeyDict: { [key: string]: string } = {
189+
"【": "[",
190+
"】": "]",
191+
";": ";",
192+
"‘": "'",
193+
"’": "'",
194+
"“": '"',
195+
"”": '"',
196+
",": ",",
197+
"。": ".",
198+
"、": "\\",
199+
"《": "<",
200+
"》": ">",
201+
"?": "?",
202+
"!": "!",
203+
":": ":",
204+
"·": "`",
205+
"¥": "$",
206+
"~": "~",
207+
"……": "^",
208+
"|": "|",
209+
};
210+
const transedKey = transedKeyDict[currentKey];
211+
if (currentKey === transedKey) {
212+
matchKey = true;
213+
}
214+
}
170215
const matchButton = event instanceof MouseEvent && event.button === this.button;
171216
const matchWheel =
172217
event instanceof WheelEvent &&

0 commit comments

Comments
 (0)