feat(ui): enhance item update logic with active filter handling

* Added logic to reapply filters when updating an item if an active filter exists.
* Ensured items are updated directly when no filter is active.
* Updated `updateItems` method to filter items based on the current filter text after updating the original items.
This commit is contained in:
qianlifeng 2025-05-29 09:21:58 +08:00
parent b0a1405d12
commit 872e2873be
No known key found for this signature in database
1 changed files with 12 additions and 9 deletions

View File

@ -197,20 +197,23 @@ class WoxListController<T> extends GetxController {
_originalItems[originalIndex] = item;
}
// update items
final index = _items.indexWhere((element) => element.value.id == item.id);
if (index != -1) {
_items[index] = item.obs;
// Check if there's an active filter
bool hasActiveFilter = filterBoxController.text.isNotEmpty;
if (hasActiveFilter) {
// If there's an active filter, reapply it to ensure the updated item is properly filtered
filterItems(traceId, filterBoxController.text);
} else {
// No filter active, update items directly
final index = _items.indexWhere((element) => element.value.id == item.id);
if (index != -1) {
_items[index] = item.obs;
}
}
}
void updateItems(String traceId, List<WoxListItem<T>> newItems) {
_items.assignAll(newItems.map((item) => item.obs));
_originalItems.assignAll(newItems);
if (_activeIndex.value >= _items.length && _items.isNotEmpty) {
updateActiveIndex(traceId, 0);
}
filterItems(traceId, filterBoxController.text);
}
void updateHoveredIndex(int index) {