mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-10-31 15:21:46 +09:00
同じホットキーが連続で発動しないように (#6082)
* add cooldown to hotkey * remove blank * use repeat flag * format * Add Repeatable option to Hotkey * Boolean型のみに * console.log消すの忘れてた
This commit is contained in:
parent
03f54c5b02
commit
569be15705
@ -12,14 +12,22 @@ type action = {
|
|||||||
patterns: pattern[];
|
patterns: pattern[];
|
||||||
|
|
||||||
callback: Function;
|
callback: Function;
|
||||||
|
|
||||||
|
allowRepeat: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getKeyMap = keymap => Object.entries(keymap).map(([patterns, callback]): action => {
|
const getKeyMap = keymap => Object.entries(keymap).map(([patterns, callback]): action => {
|
||||||
const result = {
|
const result = {
|
||||||
patterns: [],
|
patterns: [],
|
||||||
callback: callback
|
callback: callback,
|
||||||
|
allowRepeat: true
|
||||||
} as action;
|
} as action;
|
||||||
|
|
||||||
|
if (patterns.match(/^\(.*\)$/) !== null) {
|
||||||
|
result.allowRepeat = false;
|
||||||
|
patterns = patterns.slice(1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
result.patterns = patterns.split('|').map(part => {
|
result.patterns = patterns.split('|').map(part => {
|
||||||
const pattern = {
|
const pattern = {
|
||||||
which: [],
|
which: [],
|
||||||
@ -77,6 +85,7 @@ export default {
|
|||||||
const matched = match(e, action.patterns);
|
const matched = match(e, action.patterns);
|
||||||
|
|
||||||
if (matched) {
|
if (matched) {
|
||||||
|
if (!action.allowRepeat && e.repeat) return;
|
||||||
if (el._hotkey_global && match(e, targetReservedKeys)) return;
|
if (el._hotkey_global && match(e, targetReservedKeys)) return;
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user