tap method

void tap(
  1. BuildContext context,
  2. VEntity ent
)

Implementation

void tap(BuildContext context, VEntity ent) async {
  if (_lastTapped == ent &&
      DateTime.now().millisecondsSinceEpoch - _lastTappedTime! < 500) {
    tapOpen(context, ent);
  } else {
    bool inSelection = selection.value.contains(ent);

    if (HardwareKeyboard.instance.isShiftPressed && _lastTapped != null) {
      List<VEntity> view = await getChildren(
        workingVFolder.value,
      ).toList();

      int start = view.indexOf(_lastTapped!);
      int end = view.indexOf(ent);

      if (start < 0 || end < 0) {
        selection.add([ent]);
      } else {
        List<VEntity> newSelection = [];
        int a = min(start, end);
        int b = max(start, end);

        for (int i = a; i <= b; i++) {
          newSelection.add(view[i]);
        }

        selection.add(newSelection);
      }
    } else if (HardwareKeyboard.instance.isControlPressed) {
      if (inSelection) {
        selection.add([...selection.value.where((e) => e != ent)]);
      } else {
        selection.add([...selection.value, ent]);
      }
    } else {
      selection.add([ent]);
    }

    _lastTapped = ent;
    _lastTappedTime = DateTime.now().millisecondsSinceEpoch;
  }
}