From 569be15705b570d5295e2dc9a1af4b2e6a0a725f Mon Sep 17 00:00:00 2001 From: Oni-Men Date: Wed, 26 Feb 2020 17:22:43 +0900 Subject: 同じホットキーが連続で発動しないように (#6082) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add cooldown to hotkey * remove blank * use repeat flag * format * Add Repeatable option to Hotkey * Boolean型のみに * console.log消すの忘れてた --- src/client/scripts/hotkey.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/client/scripts') diff --git a/src/client/scripts/hotkey.ts b/src/client/scripts/hotkey.ts index ec627ab15b..672dbedde1 100644 --- a/src/client/scripts/hotkey.ts +++ b/src/client/scripts/hotkey.ts @@ -12,14 +12,22 @@ type action = { patterns: pattern[]; callback: Function; + + allowRepeat: boolean; }; const getKeyMap = keymap => Object.entries(keymap).map(([patterns, callback]): action => { const result = { patterns: [], - callback: callback + callback: callback, + allowRepeat: true } as action; + if (patterns.match(/^\(.*\)$/) !== null) { + result.allowRepeat = false; + patterns = patterns.slice(1, -1); + } + result.patterns = patterns.split('|').map(part => { const pattern = { which: [], @@ -77,6 +85,7 @@ export default { const matched = match(e, action.patterns); if (matched) { + if (!action.allowRepeat && e.repeat) return; if (el._hotkey_global && match(e, targetReservedKeys)) return; e.preventDefault(); -- cgit v1.2.3-freya