buttonDown method Null safety

  1. @override
void buttonDown(
  1. Operation key
)
override

Implementation

@override
void buttonDown(Operation key) {
  if (model.shift != ShiftKey.none) {
    model.shift = ShiftKey.none;
    // key.pressed(this) might set the shift key again.
  }
  if (key == Operations.gto && controller is RealController) {
    // This is a little tricky.  GTO has this quirk, where "GTO . nnn"
    // positions the current line.  It still enables stack lift,
    // which is what the normal key.pressed() does.
    key.pressed(this);
    changeState(WaitingForGotoDot(controller, this));
    return;
  }
  final OperationArg? arg = key.arg;
  if (arg != null) {
    const selector = _ArgOperationSelector();
    final void Function(Model, int)? f =
        model.displayMode.select(selector, arg);
    if (key.calcDefinedFor(controller, f) != null) {
      // If there's a calculation for our current mode
      controller.runWithArg(arg, this);
    } else {
      key.pressed(this); // TODO  Really?
    }
  } else {
    key.pressed(this); // TODO  Really?
    final f = getCalculation(key);
    if (f != null) {
      _calculate(f);
      key.possiblyAlterStackLift(controller);
    }
  }
}