removeNodes method

EditResult removeNodes(
  1. String id,
  2. Set<String> nodeIds
)

Removing the last segment removes its owner in the same undoable edit.

Implementation

EditResult removeNodes(String id, Set<String> nodeIds) {
  final path = _pathOf(id);
  if (path == null || nodeIds.isEmpty) {
    return const EditResult.denied(
      code: DiagramDenialCode.unsupportedOperation,
      reason: 'Select path points',
    );
  }
  if (nodeIds.any((id) => !path.nodes.any((n) => n.id == id))) {
    return const EditResult.denied(
      code: DiagramDenialCode.unsupportedOperation,
      reason: 'Unknown path point',
    );
  }
  final nodes = path.nodes.where((n) => !nodeIds.contains(n.id)).toList();
  if (nodes.length < 2) return DiagramObjectCommands(_store).remove({id});
  return _edit(
    id,
    (p) => p.copyWith(nodes: nodes, closed: p.closed && nodes.length >= 3),
  );
}