charmbracelet / charmbracelet/bubbles
Inconsistent & potentially misleading behaviour when calling List `RemoveItem`
- Dominant language
- Go
- Stars
- 8.9k
- Forks
- 457
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 5
Description
**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.
- OS [e.g. Ubuntu, macOS]: MacOS
- Shell [e.g. zsh, fish]: fish
- Terminal Emulator [e.g. kitty, iterm]: iTem
- Terminal Multiplexer [e.g. tmux]: N/A
- Locale [e.g. en_US.UTF-8, zh_CN.UTF-8, etc.]: en_US.UTF-8
**To Reproduce**
Steps to reproduce the behavior:
1. Have a list.
2. Filter such that the second item in the global list is the first item in the filtered list
3. Call `RemoveItem(0)` on the filtered list
4. Observe that the filtered list updates to show that the first item in it is removed
5. Reset the filter
6. The item removed from the filter is present, but item in position 0 is gone
Alternatively:
1. Have a list.
2. Filter such that the global index of the first item in the filtered list is beyond the length of the filter (e.g. filter is len(1) but item is in index 1 on the global list)
3. Call `RemoveItem(globalIndexOfFilteredItem)` on the filtered list
4. Observe that the filtered list does not update to show that the item has been removed
5. Reset the filter
6. Observe that the item which was still shown in the filter is no longer present in the global list
**Source 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.
Contributor guide
Assessment
This issue has not been assessed yet.