forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotkey.ts
More file actions
53 lines (46 loc) · 1.43 KB
/
hotkey.ts
File metadata and controls
53 lines (46 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { globalContext, Hotkey as InnerHotkey } from '@alilc/lowcode-editor-core';
import { hotkeySymbol } from '../symbols';
import { IPublicTypeDisposable, IPublicTypeHotkeyCallback, IPublicTypeHotkeyCallbacks, IPublicApiHotkey } from '@alilc/lowcode-types';
const innerHotkeySymbol = Symbol('innerHotkey');
export class Hotkey implements IPublicApiHotkey {
private readonly [innerHotkeySymbol]: InnerHotkey;
get [hotkeySymbol](): InnerHotkey {
if (this.workspaceMode) {
return this[innerHotkeySymbol];
}
const workspace = globalContext.get('workspace');
if (workspace.isActive) {
return workspace.window.innerHotkey;
}
return this[innerHotkeySymbol];
}
constructor(hotkey: InnerHotkey, readonly workspaceMode: boolean = false) {
this[innerHotkeySymbol] = hotkey;
}
get callbacks(): IPublicTypeHotkeyCallbacks {
return this[hotkeySymbol].callBacks;
}
/**
* @deprecated
*/
get callBacks() {
return this.callbacks;
}
/**
* 绑定快捷键
* @param combos 快捷键,格式如:['command + s'] 、['ctrl + shift + s'] 等
* @param callback 回调函数
* @param action
* @returns
*/
bind(
combos: string[] | string,
callback: IPublicTypeHotkeyCallback,
action?: string,
): IPublicTypeDisposable {
this[hotkeySymbol].bind(combos, callback, action);
return () => {
this[hotkeySymbol].unbind(combos, callback, action);
};
}
}