mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-19 22:54:31 +08:00
fix: 设置界面不能按 esc 返回
This commit is contained in:
1 parent
e666b85ba3
commit
82d58756b7
5 files changed
+61
-19
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user