Added a hotkey repeat check to avoid bugs
This commit is contained in:
parent
68c4beab46
commit
38aca6f605
@ -36,18 +36,20 @@ function isSingleLetter(value) {
|
|||||||
// Create hotkeyConfig from opts
|
// Create hotkeyConfig from opts
|
||||||
function createHotkeyConfig(defaultHotkeysConfig, hotkeysConfigOpts) {
|
function createHotkeyConfig(defaultHotkeysConfig, hotkeysConfigOpts) {
|
||||||
const result = {};
|
const result = {};
|
||||||
|
const usedKeys = new Set();
|
||||||
|
|
||||||
for (const key in defaultHotkeysConfig) {
|
for (const key in defaultHotkeysConfig) {
|
||||||
if (hotkeysConfigOpts[key] && isSingleLetter(hotkeysConfigOpts[key])) {
|
if (hotkeysConfigOpts[key] && isSingleLetter(hotkeysConfigOpts[key]) && !usedKeys.has(hotkeysConfigOpts[key].toUpperCase())) {
|
||||||
// If the property passes the test, add 'Key' before it and save it
|
// If the property passed the test and has not yet been used, add 'Key' before it and save it
|
||||||
result[key] = "Key" + hotkeysConfigOpts[key].toUpperCase();
|
result[key] = 'Key' + hotkeysConfigOpts[key].toUpperCase();
|
||||||
|
usedKeys.add(hotkeysConfigOpts[key].toUpperCase());
|
||||||
} else {
|
} else {
|
||||||
// Если свойство не прошло проверку, сохраняем значение по умолчанию
|
// If the property does not pass the test or has already been used, we keep the default value
|
||||||
console.error(
|
console.error(`Hotkey: ${hotkeysConfigOpts[key]} for ${key} is repeated and conflicts with another hotkey or is not 1 letter. The default hotkey is used: ${defaultHotkeysConfig[key]}`);
|
||||||
`Hotkey: "${hotkeysConfigOpts[key]}" for ${key}, must contain only 1 letter. The default hotkey is set: ${defaultHotkeysConfig[key][3]}`
|
|
||||||
);
|
|
||||||
result[key] = defaultHotkeysConfig[key];
|
result[key] = defaultHotkeysConfig[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user