Open g026r opened 3 weeks ago
Workaround I've found for this at the moment is to find the global index of the item being removed, and then call SetItems(slices.Delete(Items(), GlobalIndex, GlobalIndex+1))
, which triggers a filter update & results in the same item being removed from both the filtered & unfiltered lists.
It is quite obviously less than ideal. But better than the alternative of "have the correct item removed from the filtered list but have a different item removed from the global list, or have the correct item removed from the global list but different item removed from the filtered list."
If I understand the issue right: When filtering, if the item is removed from the filtered items, it doesn't remove the same item from the global list,
And ideally it should be the case where: When filtering, if the item is removed from the filtered items, it should also remove the same item from the global list
Is my understanding for it correct? If so feel free to checkout this PR https://github.com/charmbracelet/bubbles/pull/638 if this is what you had in mind related to the issue, and the fix for it
@prithvijj Something like that, yeah. Probably the simplest way to describe it is that it removes the item at that index in both the filtered & unfiltered items. But since they're filtered, the item at that index isn't the same between the two.
I'll take a look at your PR.
tbh, I found it somewhat odd that RemoveItem
operates on the filtered list to begin with. SetItem
and InsertItem
, the other two methods that operate on the a single element in the list, don't modify the filtered list; instead they only modify the full list & then return a tea.Cmd
indicating that the filter needs to be updated.
Describe the bug
RemoveItem
, when called, operates both on the unfiltered list & the filtered list resulting in misleading & inconsistent behaviour.If
index < len(filteredItems)
then filteredItems will be updated to remove the item at that index while simultaneously removing the item at the same index in the global list even if the two items do not match.If
index >= len(filteredItems)
then the global list will be updated to remove the item at that index while the filtered list is simultaneously not updated, even if the item that was removed is currently visible in the filtered list.Setup Please complete the following information along with version numbers, if applicable.
To Reproduce Steps to reproduce the behavior:
RemoveItem(0)
on the filtered listAlternatively:
RemoveItem(globalIndexOfFilteredItem)
on the filtered listSource Code Please include source code if needed to reproduce the behavior.
Expected behavior When an item is shown as being removed from the filtered list, the same item should be removed from the global list. Likewise, when an item is removed from the global list, that item should be removed from the filtered list if it is present.
Screenshots Add screenshots to help explain your problem.
Additional context Add any other context about the problem here.