feat(network): add undo/redo shortcuts (Ctrl+Z/Y) and arrow key nudging

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-04-13 20:06:33 +00:00
parent a392d24101
commit 02c19a7580
2 changed files with 46 additions and 1 deletions

View File

@@ -113,6 +113,17 @@ function DiagramEditorInner() {
const canUndo = historyIndex.current > 0
const canRedo = historyIndex.current < historyStack.current.length - 1
const onNudge = useCallback((dx: number, dy: number) => {
const selected = nodes.filter(n => n.selected)
if (selected.length === 0) return
pushHistory(nodes, edges)
setNodes(prev => prev.map(n =>
n.selected
? { ...n, position: { x: n.position.x + dx, y: n.position.y + dy } }
: n
))
}, [nodes, edges, pushHistory, setNodes])
const {
copyNodes,
pasteNodes,
@@ -127,6 +138,9 @@ function DiagramEditorInner() {
setEdges,
setIsDirty: (v: boolean) => setIsDirty(v),
canvasRef,
onUndo: undo,
onRedo: redo,
onNudge,
})
const handleNodesChange: typeof onNodesChange = useCallback((changes) => {