update method
Updates the component state in response to a message.
Returns the updated component (often this) and an optional command.
Implementation
@override
(SelectModel<T>, Cmd?) update(Msg msg) {
if (msg is KeyMsg) {
final key = msg.key;
// Check for Ctrl+C
if (key.ctrl && key.runes.isNotEmpty && key.runes.first == 0x63) {
return (this, Cmd.message(const SelectionCancelledMsg()));
}
if (keyMatches(key, [keyMap.cancel])) {
return (this, Cmd.message(const SelectionCancelledMsg()));
}
if (keyMatches(key, [keyMap.select])) {
if (_items.isNotEmpty) {
return (
this,
Cmd.message(SelectionMadeMsg<T>(_items[_cursor], _cursor)),
);
}
return (this, null);
}
if (keyMatches(key, [keyMap.up])) {
_cursorUp();
} else if (keyMatches(key, [keyMap.down])) {
_cursorDown();
} else if (keyMatches(key, [keyMap.home])) {
_goToStart();
} else if (keyMatches(key, [keyMap.end])) {
_goToEnd();
} else if (keyMatches(key, [keyMap.pageUp])) {
_pageUp();
} else if (keyMatches(key, [keyMap.pageDown])) {
_pageDown();
}
}
return (this, null);
}