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:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user