fix: shortcuts only block keyboard actions when needed, and change some keybinds
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
export const useKeyboardShortcuts = () => {
|
||||
const shortcutsMap = new Map<string, () => void>();
|
||||
const shortcutsMap = new Map<string, (event: KeyboardEvent) => void>();
|
||||
|
||||
const normalize = (combo: string[]) =>
|
||||
combo.map(k => k.toLowerCase()).sort().join('+');
|
||||
|
||||
const addShortcut = (combo: string[], callback: () => void) => {
|
||||
const addShortcut = (combo: string[], callback: (event: KeyboardEvent) => void) => {
|
||||
const normalizedKey = normalize(combo);
|
||||
shortcutsMap.set(normalizedKey, callback);
|
||||
|
||||
@@ -28,9 +28,7 @@ export const useKeyboardShortcuts = () => {
|
||||
const pressedCombo = normalize(keys);
|
||||
|
||||
if (shortcutsMap.has(pressedCombo)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
shortcutsMap.get(pressedCombo)!();
|
||||
shortcutsMap.get(pressedCombo)!(event);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user