Skip to content

Commit 7f44496

Browse files
committed
feat: debug模式下,屏幕信息左上角能够显示当前快捷键待匹配按键序列信息,以便于排查某些快捷键看上去没有匹配上的问题
1 parent b4f06f8 commit 7f44496

3 files changed

Lines changed: 20 additions & 38 deletions

File tree

app/src/core/render/canvas2d/renderer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Project, service } from "@/core/Project";
22
import { Settings } from "@/core/service/Settings";
33
import { MouseLocation } from "@/core/service/controlService/MouseLocation";
4+
import { KeyBindsUI } from "@/core/service/controlService/shortcutKeysEngine/KeyBindsUI";
45
import { StageObject } from "@/core/stage/stageObject/abstract/StageObject";
56
import { CubicCatmullRomSplineEdge } from "@/core/stage/stageObject/association/CubicCatmullRomSplineEdge";
67
import { LineEdge } from "@/core/stage/stageObject/association/LineEdge";
@@ -665,6 +666,7 @@ export class Renderer {
665666
return;
666667
}
667668

669+
const keySequence = KeyBindsUI.getCurrentKeySequence();
668670
const detailsData = [
669671
"调试信息已开启,可在设置中关闭,或快捷键关闭",
670672
`scale: ${this.project.camera.currentScale}`,
@@ -679,6 +681,7 @@ export class Renderer {
679681
`edge count: ${this.project.stageManager.getLineEdges().length}`,
680682
`section count: ${this.project.stageManager.getSections().length}`,
681683
`pressingKeys: ${this.project.controller.pressingKeysString()}`,
684+
`keySequence: ${keySequence || "(无)"}`,
682685
`鼠标按下情况: ${this.project.controller.isMouseDown}`,
683686
`框选框: ${JSON.stringify(this.project.rectangleSelect.getRectangle())}`,
684687
`正在切割: ${this.project.controller.cutting.isUsing}`,

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

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Vector } from "@graphif/data-structures";
66
import { getTextSize } from "@/utils/font";
77
import { KeyBindsUI, type UIKeyBind } from "./KeyBindsUI";
88
import { formatKeyBindSequenceToString } from "@/utils/keyDisplay";
9+
import i18next from "i18next";
910

1011
/**
1112
* 快捷键提示引擎
@@ -173,45 +174,12 @@ export class KeyBindHintEngine {
173174

174175
/**
175176
* 获取快捷键标题
177+
* 从 i18n 翻译文件中读取
176178
*/
177179
private getKeyBindTitle(id: string): string {
178-
const titleMap: Record<string, string> = {
179-
saveFile: "保存文件",
180-
openFile: "打开文件",
181-
newDraft: "新建草稿",
182-
undo: "撤销",
183-
redo: "重做",
184-
copy: "复制",
185-
paste: "粘贴",
186-
selectAll: "全选",
187-
deleteSelectedStageObjects: "删除",
188-
resetView: "重置视野",
189-
toggleFullscreen: "全屏切换",
190-
closeAllSubWindows: "关闭子窗口",
191-
searchText: "搜索",
192-
editEntityDetails: "编辑详情",
193-
createTextNodeFromCameraLocation: "创建节点",
194-
selectUp: "向上选择",
195-
selectDown: "向下选择",
196-
selectLeft: "向左选择",
197-
selectRight: "向右选择",
198-
moveUpSelectedEntities: "向上移动",
199-
moveDownSelectedEntities: "向下移动",
200-
moveLeftSelectedEntities: "向左移动",
201-
moveRightSelectedEntities: "向右移动",
202-
folderSection: "折叠/展开章节",
203-
packEntityToSection: "打包到章节",
204-
reverseEdges: "反向边",
205-
generateNodeTreeWithDeepMode: "深度生成节点",
206-
generateNodeTreeWithBroadMode: "广度生成节点",
207-
switchActiveProject: "切换项目",
208-
checkoutProtectPrivacy: "隐私模式",
209-
openColorPanel: "颜色面板",
210-
switchDebugShow: "调试显示",
211-
setWindowToMiniSize: "迷你窗口",
212-
};
213-
214-
return titleMap[id] || id;
180+
// 使用 i18next 直接从翻译文件读取
181+
const translation = i18next.t(`${id}.title`, { ns: "keyBinds", defaultValue: "" });
182+
return translation || id;
215183
}
216184

217185
/**

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { matchEmacsKeyPress, transEmacsKeyWinToMac } from "@/utils/emacs";
1+
import { formatEmacsKey, matchEmacsKeyPress, transEmacsKeyWinToMac } from "@/utils/emacs";
22
import { isMac } from "@/utils/platform";
33
import { createStore } from "@/utils/store";
44
import { Queue } from "@graphif/data-structures";
@@ -342,4 +342,15 @@ export namespace KeyBindsUI {
342342
enqueue(event);
343343
check();
344344
}
345+
346+
/**
347+
* 获取当前按键序列的字符串表示
348+
* 用于在debug模式下显示当前已按下的按键序列
349+
*/
350+
export function getCurrentKeySequence(): string {
351+
if (userEventQueue.length === 0) {
352+
return "";
353+
}
354+
return userEventQueue.arrayList.map((event) => formatEmacsKey(event)).join(" ");
355+
}
345356
}

0 commit comments

Comments
 (0)