From 872e2873be5dc7425e33096ab9b3f094126dfcc4 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Thu, 29 May 2025 09:21:58 +0800 Subject: [PATCH] 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. --- .../lib/controllers/wox_list_controller.dart | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/wox.ui.flutter/wox/lib/controllers/wox_list_controller.dart b/wox.ui.flutter/wox/lib/controllers/wox_list_controller.dart index c4468ab1..1dd53fc7 100644 --- a/wox.ui.flutter/wox/lib/controllers/wox_list_controller.dart +++ b/wox.ui.flutter/wox/lib/controllers/wox_list_controller.dart @@ -197,20 +197,23 @@ class WoxListController 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> 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) {