Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions client/src/controllers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
deleteLoop,
deleteNode,
deleteStock,
updateEdge,
} from "@/actions/graph";
import { isCloudId, isEdgeId, isFlowId, isLoopId, isNodeId, isStockId } from "@/models/graph";
import { useInteractionStore } from "@/stores/interaction";
Expand All @@ -24,9 +25,17 @@ export function useCommands() {
clearSelectedIds();
};

const updateEdgePolarities = (ids: string[], patch: Partial<{ polarity: "+" | "-" }>) => {
ids.forEach((id) => {
if (isEdgeId(id)) updateEdge(id, patch);
});
};

return {
deleteSelectedIds: () => deleteIds(selectedIds),
deleteId: (id: string) => deleteIds([id]),
updateSelectedEdgePolarities: (polarity: "+" | "-") =>
updateEdgePolarities(selectedIds, { polarity }),
cancelSelection: () => clearSelectedIds(),
};
}
19 changes: 15 additions & 4 deletions client/src/controllers/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useEffect } from "react";

import { useCommands } from "@/controllers/command";
import { useInteractionStore } from "@/stores/interaction";

import { useCommands } from "./command";

export function useKeyboardShortcuts() {
const { setInteractionMode, toggleInspectorOpen } = useInteractionStore();
const { deleteSelectedIds, cancelSelection } = useCommands();
const { deleteSelectedIds, cancelSelection, updateSelectedEdgePolarities } = useCommands();

useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
Expand All @@ -33,6 +32,12 @@ export function useKeyboardShortcuts() {
cancelSelection();
setInteractionMode("select");
break;
case "+":
updateSelectedEdgePolarities("+");
break;
case "-":
updateSelectedEdgePolarities("-");
break;
case "Backspace":
case "Delete":
deleteSelectedIds();
Expand All @@ -42,5 +47,11 @@ export function useKeyboardShortcuts() {

window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
}, [deleteSelectedIds, cancelSelection, setInteractionMode, toggleInspectorOpen]);
}, [
deleteSelectedIds,
cancelSelection,
updateSelectedEdgePolarities,
setInteractionMode,
toggleInspectorOpen,
]);
}
26 changes: 15 additions & 11 deletions client/src/views/help/HelpModalView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { Fragment, useState } from "react";
import { LuCircleHelp } from "react-icons/lu";

import { Button } from "@/components/ui/button";
Expand All @@ -14,9 +14,11 @@ export function HelpModalView() {
const [isOpen, setIsOpen] = useState(false);

const shortcuts = [
{ keys: ["Ctrl", "\\"], description: "Toggle Inspector Sidebar" },
{ keys: ["Ctrl / ⌘", "\\"], description: "Toggle Inspector Sidebar" },
{ keys: ["+"], description: "Set Selected Edges' Polarity to Positive" },
{ keys: ["-"], description: "Set Selected Edges' Polarity to Negative" },
{ keys: ["Esc"], description: "Clear Selection & Select Mode" },
{ keys: ["Del"], description: "Delete Selected Items" },
{ keys: ["Del / ⌫"], description: "Delete Selected Items" },
];

return (
Expand Down Expand Up @@ -45,14 +47,16 @@ export function HelpModalView() {
<span className="text-sm text-muted-foreground font-medium">
{s.description}
</span>
<div className="flex gap-1">
{s.keys.map((key) => (
<kbd
key={key}
className="pointer-events-none inline-flex h-7 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-bold opacity-100"
>
{key === "\\" ? " \u005C " : key}
</kbd>
<div className="flex items-center gap-1.5">
{s.keys.map((key, index) => (
<Fragment key={key}>
<kbd className="pointer-events-none inline-flex min-w-[1.75rem] h-7 select-none items-center justify-center rounded border bg-muted px-1.5 font-mono text-[10px] font-bold opacity-100">
{key === "\\" ? "\u005C" : key}
</kbd>
{index < s.keys.length - 1 && (
<span className="text-muted-foreground text-xs">+</span>
)}
</Fragment>
))}
</div>
</div>
Expand Down
Loading