Feat: User can customize all shortcuts
This commit is contained in:
parent
c146a0c828
commit
76f3b82412
5 changed files with 43 additions and 10 deletions
|
|
@ -10,6 +10,7 @@ import { classNames } from "../../utils/utils";
|
||||||
import ForwardedIconComponent from "../genericIconComponent";
|
import ForwardedIconComponent from "../genericIconComponent";
|
||||||
import { Separator } from "../ui/separator";
|
import { Separator } from "../ui/separator";
|
||||||
import { useHotkeys } from "react-hotkeys-hook";
|
import { useHotkeys } from "react-hotkeys-hook";
|
||||||
|
import { useShortcutsStore } from "../../stores/shortcuts";
|
||||||
|
|
||||||
export default function FlowToolbar(): JSX.Element {
|
export default function FlowToolbar(): JSX.Element {
|
||||||
function handleAPIWShortcut(e: KeyboardEvent) {
|
function handleAPIWShortcut(e: KeyboardEvent) {
|
||||||
|
|
@ -24,8 +25,11 @@ export default function FlowToolbar(): JSX.Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useHotkeys("mod+k", handleChatWShortcut);
|
const openPlayground = useShortcutsStore(state => state.open);
|
||||||
useHotkeys("mod+r", handleAPIWShortcut);
|
const api = useShortcutsStore(state => state.api);
|
||||||
|
|
||||||
|
useHotkeys(openPlayground, handleChatWShortcut);
|
||||||
|
useHotkeys(api, handleAPIWShortcut);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [openCodeModal, setOpenCodeModal] = useState<boolean>(false);
|
const [openCodeModal, setOpenCodeModal] = useState<boolean>(false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -832,7 +832,23 @@ export const defaultShortcuts = [
|
||||||
{
|
{
|
||||||
name: "Redo",
|
name: "Redo",
|
||||||
shortcut: "Ctrl + y"
|
shortcut: "Ctrl + y"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
name: "Group",
|
||||||
|
shortcut: "Ctrl + g"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Cut",
|
||||||
|
shortcut: "Ctrl + x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Paste",
|
||||||
|
shortcut: "Ctrl + v"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "API",
|
||||||
|
shortcut: "Ctrl + r"
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const unavailableShortcutss = ["CTRL + SHIFT + A", "CTRL + Q", "CTRL + SHIFT + U", "CTRL + C", "CTRL + D", "CTRL + SHIFT + S", "CTRL + SHIFT + D", "CTRL + S", "BACKSPACE", "CTRL + K", "CTRL + Z", "CTRL + Y"];
|
export const unavailableShortcutss = ["CTRL + R","CTRL + V", "CTRL + X", "CTRL + G", "CTRL + SHIFT + A", "CTRL + Q", "CTRL + SHIFT + U", "CTRL + C", "CTRL + D", "CTRL + SHIFT + S", "CTRL + SHIFT + D", "CTRL + S", "BACKSPACE", "CTRL + K", "CTRL + Z", "CTRL + Y"];
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ export default function Page({
|
||||||
|
|
||||||
function handleDelete(e: KeyboardEvent) {
|
function handleDelete(e: KeyboardEvent) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!isWrappedWithClass(event, "nodelete") && lastSelection) {
|
if (!isWrappedWithClass(e, "nodelete") && lastSelection) {
|
||||||
takeSnapshot();
|
takeSnapshot();
|
||||||
deleteNode(lastSelection.nodes.map((node) => node.id));
|
deleteNode(lastSelection.nodes.map((node) => node.id));
|
||||||
deleteEdge(lastSelection.edges.map((edge) => edge.id));
|
deleteEdge(lastSelection.edges.map((edge) => edge.id));
|
||||||
|
|
@ -245,15 +245,20 @@ export default function Page({
|
||||||
const undoAction = useShortcutsStore(state => state.undo);
|
const undoAction = useShortcutsStore(state => state.undo);
|
||||||
const redoAction = useShortcutsStore(state => state.redo);
|
const redoAction = useShortcutsStore(state => state.redo);
|
||||||
const copyAction = useShortcutsStore(state => state.copy);
|
const copyAction = useShortcutsStore(state => state.copy);
|
||||||
|
const duplicate = useShortcutsStore(state => state.duplicate);
|
||||||
|
const deleteAction = useShortcutsStore(state => state.delete);
|
||||||
|
const groupAction = useShortcutsStore(state => state.group);
|
||||||
|
const cutAction = useShortcutsStore(state => state.cut);
|
||||||
|
const pasteAction = useShortcutsStore(state => state.paste);
|
||||||
|
|
||||||
useHotkeys(undoAction, handleUndo);
|
useHotkeys(undoAction, handleUndo);
|
||||||
useHotkeys(redoAction, handleRedo);
|
useHotkeys(redoAction, handleRedo);
|
||||||
useHotkeys("mod+g", handleGroup);
|
useHotkeys(groupAction, handleGroup);
|
||||||
useHotkeys("mod+d", handleDuplicate);
|
useHotkeys(duplicate, handleDuplicate);
|
||||||
useHotkeys(copyAction, handleCopy);
|
useHotkeys(copyAction, handleCopy);
|
||||||
useHotkeys("mod+x", handleCut);
|
useHotkeys(cutAction, handleCut);
|
||||||
useHotkeys("mod+v", handlePaste);
|
useHotkeys(pasteAction, handlePaste);
|
||||||
useHotkeys("backspace", handleDelete);
|
useHotkeys(deleteAction, handleDelete);
|
||||||
useHotkeys("delete", handleDelete);
|
useHotkeys("delete", handleDelete);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ export const useShortcutsStore = create<shortcutsStoreType>((set, get) => ({
|
||||||
docs: "mod+shift+d",
|
docs: "mod+shift+d",
|
||||||
save: "mod+s",
|
save: "mod+s",
|
||||||
delete: "backspace",
|
delete: "backspace",
|
||||||
|
group: "mod+g",
|
||||||
|
cut: "mod+x",
|
||||||
|
paste: "mod+v",
|
||||||
|
api: "mod+r",
|
||||||
updateUniqueShortcut: (name, combination) => {
|
updateUniqueShortcut: (name, combination) => {
|
||||||
set({
|
set({
|
||||||
[name]: combination
|
[name]: combination
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,10 @@ export type StoreComponentResponse = {
|
||||||
|
|
||||||
export type shortcutsStoreType = {
|
export type shortcutsStoreType = {
|
||||||
updateUniqueShortcut: (name: string, combination: string) => void;
|
updateUniqueShortcut: (name: string, combination: string) => void;
|
||||||
|
group: string;
|
||||||
|
cut: string;
|
||||||
|
paste: string;
|
||||||
|
api: string;
|
||||||
open: string;
|
open: string;
|
||||||
undo: string;
|
undo: string;
|
||||||
redo: string;
|
redo: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue