fix: 设置界面不能按 esc 返回

This commit is contained in:
AncTe committed 2025-09-25 18:42:27 +08:00
1 parent e666b85ba3
commit 82d58756b7
5 files changed
+61 -19

No files matched your search

+2 -3
View File
@@ -34,9 +34,8 @@ export function deleteWith<T>(arr: T[], ele: T): T[] {
export function spliceBy<T>(arr: T[], from: T): T[] {
const index = arr.indexOf(from);
if (index === -1) return arr;
arr.splice(index);
return arr;
if (index === -1) return [];
return arr.splice(index);
}
/**
+8 -5
View File
@@ -179,7 +179,8 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
* @param symbol 当前作用域的symbol
*/
use(symbol: symbol): void {
spliceBy(this.scopeStack, symbol);
if (symbol === this.scope) return;
this.dispose(symbol);
this.scopeStack.push(symbol);
this.scope = symbol;
this.conditionMap.set(symbol, () => true);
@@ -190,10 +191,12 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
* @param symbol 要释放的作用域的symbol
*/
dispose(symbol: symbol = this.scopeStack.at(-1) ?? Symbol()): void {
for (const key of Object.values(this.data)) {
key.emits.delete(symbol);
}
spliceBy(this.scopeStack, symbol);
const disposed = spliceBy(this.scopeStack, symbol);
disposed.forEach(v => {
for (const key of Object.values(this.data)) {
key.emits.delete(v);
}
});
this.scope = this.scopeStack.at(-1) ?? Symbol();
}