深度画布键盘事件-撤回功能

This commit is contained in:
lzp
2026-03-12 11:40:48 +08:00
parent adf562bbe4
commit 86f1efbf43
11 changed files with 228 additions and 951 deletions

View File

@@ -0,0 +1,35 @@
export class KeyEventManager {
stateManager: any
constructor(options) {
this.stateManager = options.stateManager;
this.registerEvents()
}
/** 处理键盘事件 */
handleKeyDown(event: any) {
const ctrl = event.ctrlKey ? 'ctrl-' : "";
const shift = event.shiftKey ? 'shift-' : "";
const key = event.key;
const reg = new RegExp(`^${ctrl}${shift}${key}$`, 'i')
const list = [
// { key: "ctrl-c", handler: () => this.handleCopy(event) },
// { key: "delete", handler: () => this.handleDelete(event) },
{ key: "ctrl-z", handler: () => this.stateManager.undoState() },
{ key: "ctrl-shift-z", handler: () => this.stateManager.redoState() },
]
list.forEach((v: any) => {
if (reg.test(v.key)) v.handler(event)
})
}
/** 注册事件 */
registerEvents() {
document.addEventListener('keydown', this.handleKeyDown.bind(this))
}
/** 删除事件 */
removeEvents() {
document.removeEventListener('keydown', this.handleKeyDown.bind(this))
}
dispose() {
this.removeEvents()
}
}