Import it from @grafloria/engine.
Also has every member of MacroCommand, Command, listed on their own entries.
CutCommand = {@link CopyCommand} + {@link DeleteSelectionCommand}, executed as ONE undoable step (a {@link MacroCommand}): the selection lands on the clipboard and is removed from the diagram, and a single undo brings it back.
Two inherited behaviours had to be overridden — both are load-bearing:
-
canUndo. {@link MacroCommand.canUndo} is the AND of its steps, and {@link CopyCommand.canUndo} returns FALSE by design (a copy mutates nothing, so it has nothing to undo). The inherited implementation would therefore report a Cut as un-undoable andCommandManager.undo()would throwCannot undo command: Cut. A cut is undoable exactly when its delete half is. -
redo. The default redo re-runsexecute(), which re-runs the COPY step — and copy reads the CURRENT selection.undo()restores the entities but NOT the selection, so that copy would throwNo nodes selected. The clipboard already holds this cut's payload, so a redo is precisely "delete those same entities again", which the delete half can replay from its own recorded data.
tsclass CutCommand extends MacroCommand
Methods
constructor(clipboard: ClipboardManager, options: CutCommandOptions = {})override canExecute(context: CommandContext): boolean— A cut needs something to copy: CopyCommand has no link-only payload, so a selection of links alone cannot be cut (it can still be deleted).override canUndo(context: CommandContext): boolean— See class docs (1): copy is non-undoable by design; the delete half decides.override async redo(context: CommandContext): Promise<void>— See class docs (2): replay the delete from its recorded data, never the copy.override getDescription(): string— Get description for UI
Was this page helpful?