mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 09:38:29 +02:00
Hotkey for creating environment when dialog open
This commit is contained in:
@@ -98,6 +98,8 @@ export const EnvironmentEditDialog = function ({ initialEnvironment }: Props) {
|
|||||||
<IconButton
|
<IconButton
|
||||||
size="sm"
|
size="sm"
|
||||||
iconSize="md"
|
iconSize="md"
|
||||||
|
hotkeyAction="model.create"
|
||||||
|
hotkeyPriority={999}
|
||||||
title="Add sub environment"
|
title="Add sub environment"
|
||||||
icon="plus_circle"
|
icon="plus_circle"
|
||||||
iconClassName="text-text-subtlest group-hover:text-text-subtle"
|
iconClassName="text-text-subtlest group-hover:text-text-subtle"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export type ButtonProps = Omit<HTMLAttributes<HTMLButtonElement>, 'color' | 'onC
|
|||||||
leftSlot?: ReactNode;
|
leftSlot?: ReactNode;
|
||||||
rightSlot?: ReactNode;
|
rightSlot?: ReactNode;
|
||||||
hotkeyAction?: HotkeyAction;
|
hotkeyAction?: HotkeyAction;
|
||||||
|
hotkeyPriority?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
|
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
|
||||||
@@ -39,6 +40,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
|
|||||||
rightSlot,
|
rightSlot,
|
||||||
disabled,
|
disabled,
|
||||||
hotkeyAction,
|
hotkeyAction,
|
||||||
|
hotkeyPriority,
|
||||||
title,
|
title,
|
||||||
onClick,
|
onClick,
|
||||||
...props
|
...props
|
||||||
@@ -94,9 +96,13 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
|
|||||||
() => buttonRef.current,
|
() => buttonRef.current,
|
||||||
);
|
);
|
||||||
|
|
||||||
useHotKey(hotkeyAction ?? null, () => {
|
useHotKey(
|
||||||
buttonRef.current?.click();
|
hotkeyAction ?? null,
|
||||||
});
|
() => {
|
||||||
|
buttonRef.current?.click();
|
||||||
|
},
|
||||||
|
{ priority: hotkeyPriority },
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ export function useHotKey(
|
|||||||
return [...without, newCb];
|
return [...without, newCb];
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
jotaiStore.set(callbacksAtom, (prev) => prev.filter((cb) => cb.action !== action));
|
jotaiStore.set(callbacksAtom, (prev) => prev.filter((cb) => cb.callback !== callback));
|
||||||
};
|
};
|
||||||
}, [action, callback, options]);
|
}, [action, callback, options]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user