Skip to content

Commit

Permalink
fix: fix hotkey press while msg/input leading to crash
Browse files Browse the repository at this point in the history
  • Loading branch information
srg-kostyrko committed Jan 16, 2024
1 parent db525b7 commit 740816b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions libs/game-state/src/hotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export function setupGlobalHotKeys(): void {
export function setupCustomHotKeys(map: Record<string, string>): void {
for (const [key, value] of Object.entries(map)) {
Mousetrap.bind(key, () => {
if (isPaused$.value) return;
qspApi$.value?.execLoc(value);
return false;
});
Expand Down
9 changes: 8 additions & 1 deletion libs/game-state/src/input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { create } from 'xoid';
import { isPaused$ } from './counter';

interface InputAtom {
isOpen: boolean;
Expand Down Expand Up @@ -26,6 +27,7 @@ export const input$ = create<InputAtom, InputAtomActions>(
const entered$ = atom.focus((s) => s.entered);
return {
open(content: string, onfinished: (result: string) => void): void {
isPaused$.set(true);
atom.set({
isOpen: true,
content,
Expand All @@ -39,17 +41,22 @@ export const input$ = create<InputAtom, InputAtomActions>(
finish(): void {
if (isOpen$.value) {
isOpen$.set(false);
isPaused$.set(false);
atom.value.onfinished?.(entered$.value);
}
},
close(): void {
if (isOpen$.value) {
isOpen$.set(false);
isPaused$.set(false);
atom.value.onfinished?.('');
}
},
clear(): void {
if (isOpen$.value) atom.value.onfinished?.('');
if (isOpen$.value) {
atom.value.onfinished?.('');
isPaused$.set(false);
}
atom.set({
isOpen: false,
content: '',
Expand Down
8 changes: 7 additions & 1 deletion libs/game-state/src/msg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { create } from 'xoid';
import { isPaused$ } from './counter';

interface MsgAtom {
isOpen: boolean;
Expand All @@ -21,6 +22,7 @@ export const msg$ = create<MsgAtom, MsgAtomAction>(
const isOpen$ = atom.focus((s) => s.isOpen);
return {
open(content: string, onclosed: () => void): void {
isPaused$.set(true);
atom.set({
isOpen: true,
content,
Expand All @@ -29,12 +31,16 @@ export const msg$ = create<MsgAtom, MsgAtomAction>(
},
close(): void {
if (isOpen$.value) {
isPaused$.set(false);
isOpen$.set(false);
atom.value.onclosed?.();
}
},
clear(): void {
if (isOpen$.value) atom.value.onclosed?.();
if (isOpen$.value) {
isPaused$.set(false);
atom.value.onclosed?.();
}
atom.set({
isOpen: false,
content: '',
Expand Down

0 comments on commit 740816b

Please sign in to comment.