mirror of
https://github.com/mifi/lossless-cut.git
synced 2024-11-22 02:12:30 +01:00
parent
b6645fa445
commit
f4cfe72b4b
@ -707,25 +707,37 @@ const KeyboardShortcuts = memo(({
|
|||||||
|
|
||||||
const stringifyKeys = (keys: string[]) => keys.join('+');
|
const stringifyKeys = (keys: string[]) => keys.join('+');
|
||||||
|
|
||||||
const onNewKeyBindingConfirmed = useCallback((action: KeyboardAction, keys: string[]) => {
|
const onNewKeyBindingConfirmed = useCallback(async (action: KeyboardAction, keys: string[]) => {
|
||||||
const fixedKeys = fixKeys(keys);
|
const fixedKeys = fixKeys(keys);
|
||||||
if (fixedKeys.length === 0) return;
|
if (fixedKeys.length === 0) return;
|
||||||
const keysStr = stringifyKeys(fixedKeys);
|
const keysStr = stringifyKeys(fixedKeys);
|
||||||
console.log('new key binding', action, keysStr);
|
console.log('new key binding', action, keysStr);
|
||||||
|
|
||||||
setKeyBindings((existingBindings) => {
|
const duplicate = keyBindings.find((existingBinding) => existingBinding.keys === keysStr);
|
||||||
const duplicate = existingBindings.find((existingBinding) => existingBinding.keys === keysStr);
|
let shouldReplaceDuplicate: KeyBinding | undefined;
|
||||||
if (duplicate) {
|
if (duplicate) {
|
||||||
Swal.fire({ icon: 'error', title: t('Duplicate keyboard combination'), text: t('Combination is already bound to "{{alreadyBoundKey}}"', { alreadyBoundKey: actionsMap[duplicate.action]?.name }) });
|
const { isConfirmed } = await Swal.fire({
|
||||||
console.log('trying to add duplicate');
|
icon: 'warning',
|
||||||
return existingBindings;
|
title: t('Duplicate keyboard combination'),
|
||||||
|
text: t('Combination is already bound to "{{alreadyBoundKey}}". Do you want to replace the existing binding?', { alreadyBoundKey: actionsMap[duplicate.action]?.name }),
|
||||||
|
confirmButtonText: t('Replace'),
|
||||||
|
focusCancel: true,
|
||||||
|
showCancelButton: true,
|
||||||
|
});
|
||||||
|
if (isConfirmed) {
|
||||||
|
shouldReplaceDuplicate = duplicate;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('saving key binding');
|
setKeyBindings((existingBindings) => {
|
||||||
|
console.log('Saving key binding');
|
||||||
setCreatingBinding(undefined);
|
setCreatingBinding(undefined);
|
||||||
return [...existingBindings, { action, keys: keysStr }];
|
const filtered = !shouldReplaceDuplicate ? existingBindings : existingBindings.filter((existing) => existing.keys !== shouldReplaceDuplicate.keys);
|
||||||
|
return [...filtered, { action, keys: keysStr }];
|
||||||
});
|
});
|
||||||
}, [actionsMap, setKeyBindings, t]);
|
}, [actionsMap, keyBindings, setKeyBindings, t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
Loading…
Reference in New Issue
Block a user