mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-09-24 15:49:09 +00:00
0222736349
When the keyboard shortcut scheme is off, snippet recording still treated default Mac and PC bindings as occupied. Conflict checks now use only bindings that can actually fire, and the error names the conflicting action. Closes #3025
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import {
|
|
type HotkeyScheme,
|
|
type KeyBinding,
|
|
keyStringToKeyboardEvent,
|
|
matchesKeyBinding,
|
|
} from './models/keyBindings.ts';
|
|
|
|
export type ActiveSystemBinding = {
|
|
binding: KeyBinding;
|
|
key: string;
|
|
isMac: boolean;
|
|
};
|
|
|
|
/** App shortcuts that can actually fire for the current scheme. */
|
|
export const listActiveSystemBindings = (
|
|
hotkeyScheme: HotkeyScheme,
|
|
keyBindings: readonly KeyBinding[],
|
|
): ActiveSystemBinding[] => {
|
|
if (hotkeyScheme === 'disabled') return [];
|
|
|
|
return keyBindings.flatMap((binding) => {
|
|
if (hotkeyScheme === 'mac') {
|
|
return binding.mac && binding.mac !== 'Disabled'
|
|
? [{ binding, key: binding.mac, isMac: true }]
|
|
: [];
|
|
}
|
|
|
|
if (hotkeyScheme === 'pc') {
|
|
return binding.pc && binding.pc !== 'Disabled'
|
|
? [{ binding, key: binding.pc, isMac: false }]
|
|
: [];
|
|
}
|
|
|
|
return [];
|
|
});
|
|
};
|
|
|
|
export const findActiveSystemShortcutConflict = (
|
|
key: string,
|
|
hotkeyScheme: HotkeyScheme,
|
|
keyBindings: readonly KeyBinding[],
|
|
): KeyBinding | null => {
|
|
if (!key) return null;
|
|
|
|
const event = keyStringToKeyboardEvent(key);
|
|
if (!event) return null;
|
|
|
|
const conflict = listActiveSystemBindings(hotkeyScheme, keyBindings).find((entry) => (
|
|
matchesKeyBinding(event, entry.key, entry.isMac)
|
|
));
|
|
return conflict?.binding ?? null;
|
|
};
|