Skip to content

Copy, paste and duplicate

Loading interactive example…Open in new tab ↗
Opening the live canvas…

The two cards and their bound, labeled connection belong to one group. Copy original captures an immutable subtree without adding history. Paste inserts that snapshot below the original, with new element, story and block identities. The copied connection binds to the copied cards.

Duplicate original combines capture and paste. Each paste or duplicate is one undo unit; Undo removes the complete copy and Redo restores it. Repeated pastes use the same offset, so copies can overlap; drag a group to separate them.

This demonstrates the toolkit's in-memory clipboard payload. It does not request browser clipboard permissions or demonstrate cross-application clipboard formats. Reset clears the example's captured payload along with its drawing and history.

Source

dart
actions: {
  'Copy original': (session) {
    selectOriginal(session);
    payloads[session] = session.copySelection();
  },
  'Paste': (session) {
    final payload = payloads[session];
    if (payload == null) throw StateError('Copy the original group first.');
    session
        .paste(payload, offset: const DiagramPoint(0, 300))
        .requireAllowed();
  },
  'Duplicate original': (session) {
    selectOriginal(session);
    session
        .duplicateSelection(offset: const DiagramPoint(0, 300))
        .requireAllowed();
  },
},

See Session for copy, paste and duplication contracts.