void cancel()

cancel last command if exists and if

Source

void cancel() {
  if (history.isEmpty) return;

  history.removeLast();
  var prevState = apply();
  var cmd = new CancelCommand(prevState);
  update(cmd);
}