Skip to content

fix(list): RemoveItem correctly updates the filtered list when a filter is active#997

Open
troclaux wants to merge 1 commit into
charmbracelet:mainfrom
troclaux:fix/list-remove-item-with-filter
Open

fix(list): RemoveItem correctly updates the filtered list when a filter is active#997
troclaux wants to merge 1 commit into
charmbracelet:mainfrom
troclaux:fix/list-remove-item-with-filter

Conversation

@troclaux
Copy link
Copy Markdown

@troclaux troclaux commented Jun 2, 2026

Fixes #632.

Problem

RemoveItem(index) used the same index for two different purposes:

  • removing from m.items (where index is the global item position) ✓
  • removing from m.filteredItems (where index was treated as a position in the filtered slice) ✗

When a filter was applied, those two indices no longer correspond. Depending on the relative lengths, either the wrong filtered entry was removed, or a removal in the global list was not reflected in the filtered view.

Fix

Instead of removing by positional index from filteredItems, iterate over the slice and:

  • skip the filteredItem whose .index field matches the global index being removed.
  • decrement .index for every subsequent entry (since they now point one position further than their actual global slot).

The orphaned removeFilterMatchFromSlice helper is deleted.

…er is active

RemoveItem was removing by positional index from both the global items slice
and the filteredItems slice. When a filter was applied those two indices do
not correspond, so the wrong item could be dropped from the filtered list, or
the filtered view could fail to reflect a removal that was visible inside it.

Fix: iterate over filteredItems, skip the entry whose .index matches the
removed global index, and decrement .index for every entry that follows the
removed position.

Fixes charmbracelet#632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent & potentially misleading behaviour when calling List RemoveItem

1 participant