update method

  1. @override
(DataTableModel<T>, Cmd?) update(
  1. Msg msg
)
override

Updates the component state in response to a message.

Returns the updated component (often this) and an optional command.

Implementation

@override
(DataTableModel<T>, Cmd?) update(Msg msg) {
  if (msg is KeyMsg) {
    final key = msg.key;

    // Global navigation (PgUp/PgDown)
    if (keyMatches(key, [_table.keyMap.pageUp, _table.keyMap.pageDown])) {
      final (newTable, cmd) = _table.update(msg);
      _table = newTable;
      return (this, cmd);
    }

    // Selection
    if (keyMatches(key, [
      KeyBinding(keys: ['enter']),
    ])) {
      if (_table.rows.isNotEmpty) {
        final (start, _) = _paginator.getSliceBounds(_filteredItems.length);
        final selectedIdxInFiltered = start + _table.cursor;
        final selected = _filteredItems[selectedIdxInFiltered];
        return (
          this,
          Cmd.message(
            DataTableSelectionMadeMsg<T>(selected.item, selected.index),
          ),
        );
      }
    }

    // Table navigation intercepts (Up/Down)
    if (keyMatches(key, [_table.keyMap.lineUp, _table.keyMap.lineDown])) {
      _handleNavigate(up: keyMatches(key, [_table.keyMap.lineUp]));
      return (this, null);
    }

    // Cancel
    if (keyMatches(key, [
      KeyBinding(keys: ['esc']),
    ])) {
      return (this, Cmd.message(const SearchCancelledMsg()));
    }
  }

  // Mouse wheel scroll.
  //
  // Terminal decoders (key.dart _decodeX10Button / _decodeSgrButton) produce
  // wheel events with action=press, NOT action=wheel — so match on button
  // only.  We also accept action=wheel for forward-compatibility.
  if (msg is MouseMsg &&
      (msg.button == MouseButton.wheelUp ||
          msg.button == MouseButton.wheelDown)) {
    _handleNavigate(up: msg.button == MouseButton.wheelUp);
    return (this, null);
  }

  // Forward to input for filtering
  final oldQuery = _input.value;
  final (newInput, inputCmd) = _input.update(msg);
  _input = newInput;

  if (_input.value != oldQuery) {
    _runFilter();
  }

  return (this, inputCmd);
}