feat: hotkey scopeStack

This commit is contained in:
unanmed 2023-11-18 11:03:10 +08:00
parent 49e09384fa
commit ed80fba4c9

View File

@ -34,6 +34,7 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
keyMap: Map<KeyCode, HotkeyData[]> = new Map(); keyMap: Map<KeyCode, HotkeyData[]> = new Map();
private scope: symbol = Symbol(); private scope: symbol = Symbol();
private scopeStack: symbol[] = [];
constructor(id: string, name: string) { constructor(id: string, name: string) {
super(); super();
@ -80,6 +81,7 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
* @param symbol symbol * @param symbol symbol
*/ */
use(symbol: symbol) { use(symbol: symbol) {
this.scopeStack.push(symbol);
this.scope = symbol; this.scope = symbol;
for (const key of Object.values(this.data)) { for (const key of Object.values(this.data)) {
key.func.set(symbol, () => {}); key.func.set(symbol, () => {});
@ -94,6 +96,7 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
for (const key of Object.values(this.data)) { for (const key of Object.values(this.data)) {
key.func.delete(symbol); key.func.delete(symbol);
} }
this.scope = this.scopeStack.pop() ?? Symbol();
} }
/** /**