Skip to content

Keyboard Shortcuts

The keyboard shortcuts system in ngDiagram lets users perform common actions quickly using customizable key combinations. It supports platform-specific modifier keys (automatically handling Ctrl/Cmd differences), multiple shortcuts per action, and dynamic runtime updates.

All available shortcut actions with their default key bindings. See ShortcutActionName for the complete type reference.

ActionDefault ShortcutDescription
copyCtrl/Cmd + CCopy selected elements to clipboard
cutCtrl/Cmd + XCut selected elements to clipboard
pasteCtrl/Cmd + VPaste elements from clipboard
deleteSelectionDelete or BackspaceDelete currently selected elements
selectAllCtrl/Cmd + ASelect all elements in the diagram
boxSelectionShift heldEnable box selection mode (pointer only)
multiSelectionCtrl/Cmd heldMulti-selection mode (pointer only)
keyboardMoveSelectionUpMove selected elements up
keyboardMoveSelectionDownMove selected elements down
keyboardMoveSelectionLeftMove selected elements left
keyboardMoveSelectionRightMove selected elements right
keyboardPanUpPan viewport up
keyboardPanDownPan viewport down
keyboardPanLeftPan viewport left
keyboardPanRightPan viewport right
undoCtrl/Cmd + ZUndo last action (not implemented by default; requires custom model)
redoCtrl/Cmd + YRedo last undone action (not implemented by default; requires custom model)

To override, disable, or extend default shortcuts, use the configureShortcuts() helper:

import { configureShortcuts } from 'ng-diagram';
const config = {
shortcuts: configureShortcuts([
// Override: Change paste to Ctrl+B
{
actionName: 'paste',
bindings: [{ key: 'b', modifiers: { primary: true } }],
},
// Disable: Empty bindings array
{
actionName: 'undo',
bindings: [],
},
// Multiple bindings: WSAD + Arrow keys
{
actionName: 'keyboardMoveSelectionUp',
bindings: [{ key: 'w' }, { key: 'ArrowUp' }],
},
]),
};

You can also merge custom shortcuts with existing ones at runtime:

// Get current shortcuts from the service
const currentShortcuts = ngDiagramService.config().shortcuts;
// Merge custom shortcuts with existing ones
const updatedShortcuts = configureShortcuts(
[
{
actionName: 'paste',
bindings: [{ key: 'b', modifiers: { primary: true } }],
},
],
currentShortcuts // Pass existing shortcuts as base
);
// Update the configuration
ngDiagramService.updateConfig({ shortcuts: updatedShortcuts });

configureShortcuts(customShortcuts, baseShortcuts?) merges your custom shortcuts with defaults:

  • First parameter: Custom shortcuts (overrides actions with matching actionName)
  • Second parameter: Optional base shortcuts. Defaults are used if omitted.
  • Returns: A merged shortcuts array

Unspecified actions retain their existing shortcuts.

Keyboard and pointer shortcuts in ngDiagram are defined through the ShortcutDefinition interface. A shortcut definition maps an action name to one or more key bindings (keyboard or modifier-only combinations).

Each shortcut may include:

  • One or more keyboard bindings (e.g., Ctrl + C)
  • Or one or more modifier-only bindings (e.g., Shift + click for box selection)

See ShortcutDefinition API reference.

interface InputModifiers {
primary: boolean; // Ctrl (Windows/Linux) OR Cmd (macOS) - auto-normalized
secondary: boolean; // Alt key
shift: boolean; // Shift key
meta: boolean; // Windows key or Cmd key
}

Platform normalization:

The primary modifier automatically maps to Ctrl on Windows/Linux and Cmd on macOS, allowing you to define shortcuts once that work seamlessly across platforms.

Use standard browser key names: 'a', 'b', 'Delete', 'Backspace', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', etc. Keys are case-sensitive.

See MDN KeyboardEvent.key documentation for the complete list of valid key values.

Modifier-only shortcuts (bindings without a key) are used for pointer-based interactions, such as holding Shift for box selection.

{
modifiers: {
shift: true,
}
} // Matches when Shift held during click

These shortcuts ensure that typing keys won’t accidentally trigger diagram actions.

import '@angular/compiler';
import { Component } from '@angular/core';
import { NgDiagramModelService, provideNgDiagram } from 'ng-diagram';
import { DiagramComponent } from './diagram.component';
@Component({
imports: [DiagramComponent],
template: `<shortcut-manager-example></shortcut-manager-example> `,
styles: [
`
:host {
display: flex;
position: relative;
}
`,
],
providers: [NgDiagramModelService, provideNgDiagram()],
})
export class DiagramWrapperComponent {}