Use Key Press
Shortcuts of your own: an element round the canvas hears every key pressed on the flow, so the page binds keys with ordinary @onkeydown and @onkeyup and acts through the canvas's API - AddNodes, DeleteElementsAsync and MoveSelectionAsync. The keys light up while they are held.
Press Tab to move between the nodes and edges of the diagram.
Press Enter or Space to select it, Shift with Enter to add it to the selection, the arrow keys to move the selected nodes, Delete to remove them and Escape to clear the selection. Press C to start a connection from it.
Press Enter or Space to select it, Delete to remove it and Escape to clear the selection. Press C to move its end to another node.
bit BlowTry it
- Click the canvas (or a node) so the keys reach it: the key chips above light up while you hold a key, and Last key names the latest one with its modifiers.
- Press a to add a node at a random spot; the view eases out to fit it in. Holding the key adds only one.
- Select a node and press h, j, k or l to move it left, down, up or right by 20; hold Shift for 100, or hold the key to keep it going. Several selected nodes move together.
- Select nodes or edges and press Delete or Backspace: the page removes them, along with the edges of a removed node.
- Press Ctrl+A (Cmd+A on a Mac): that one is the canvas's own select-all, and the page leaves combinations with Ctrl, Cmd or Alt alone. The arrow keys still nudge the selection too, as they always do.
How it works
@onkeydownand@onkeyupon the element round the canvas receive aKeyboardEventArgsfor every key pressed while focus is in the flow;Key,ShiftKey,CtrlKey,AltKey,MetaKeyandRepeatsay which.DeleteKeyEnabled="false"switches off the canvas's binding ofDeleteKeys(Delete and Backspace) so the page's own handler is the only one acting on them.AddNodes(node)appends and measures the new node, thenFitViewAsync(300)eases the view to fit everything over 300 ms.DeleteElementsAsync(nodes, edges)deletes the selected nodes and edges with the same rules as the Delete key: edges of a removed node go too,Deletable = falseis respected, andOnBeforeDelete,OnDeleteandNodesChangedrun as usual.MoveSelectionAsync(dx, dy)moves the selected nodes by a distance in flow units, as the arrow keys do: draggable nodes only, snapped to the grid whenSnapToGridis on, kept inside their extents, announced to a screen reader and recorded as one undo step.- The canvas claims only its own keys - the arrows, Escape, Enter and Space on a focused node,
PanActivationKey(Space) held, Ctrl/Cmd+A whileSelectAllKeyEnabled,DeleteKeys, andConnectionKey(c) on a focused node - so other letters are free for shortcuts like these. See Key Bindings for changing them.