updateItems method
Replaces source items and keeps the previously selected identity in view.
Implementation
void updateItems(List<CommandPaletteItem> value) {
final selectedId = selectedItem?.identity;
_items = List<CommandPaletteItem>.of(value);
_invalidateFilter();
final filtered = filteredItems;
if (filtered.isEmpty) {
selectedIndex = 0;
return;
}
if (selectedId != null) {
final index = filtered.indexWhere((item) => item.identity == selectedId);
if (index >= 0) {
selectedIndex = index;
return;
}
}
selectedIndex = selectedIndex.clamp(0, filtered.length - 1);
}