Skip to content

Commit

Permalink
記録するホットキーはレートリミット式にする
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Jul 9, 2024
1 parent b104485 commit 40a7509
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/frontend/src/scripts/hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,24 @@ const matchPatterns = (ev: KeyboardEvent, action: Action) => {
});
};

let lastHotKeyStoreTimer: number | null = null;

const storePattern = (ev: KeyboardEvent, callback: CallbackFunction) => {
if (lastHotKeyStoreTimer != null) {
clearTimeout(lastHotKeyStoreTimer);
}

latestHotkey = {
which: [ev.key.toLowerCase()],
ctrl: ev.ctrlKey || ev.metaKey,
alt: ev.altKey,
shift: ev.shiftKey,
callback,
};

lastHotKeyStoreTimer = window.setTimeout(() => {
latestHotkey = null;
}, 500);
};

const parseKeyCode = (input?: string | null) => {
Expand Down

0 comments on commit 40a7509

Please sign in to comment.