check shortcut length

This commit is contained in:
Gabe Yuan
2023-09-09 15:26:05 +08:00
parent 878bccf151
commit 0766199353

View File

@@ -51,9 +51,12 @@ export const shortcutListener = (fn, target = document, timeout = 3000) => {
* @param {*} target
* @returns
*/
export const shortcutRegister = (targetKeys, fn, target = document) => {
export const shortcutRegister = (targetKeys = [], fn, target = document) => {
return shortcutListener((curkeys) => {
if (isSameSet(new Set(targetKeys), new Set(curkeys))) {
if (
targetKeys.length > 0 &&
isSameSet(new Set(targetKeys), new Set(curkeys))
) {
fn();
}
}, target);