Repository navigation
Conversation
Return early for indices outside the backing list, preventing negative-index panics and preserving filters when an ignored removal has no matches. Keep the bounds guard proposed in charmbracelet#932 separate from its cursor changes. Add positive, negative, and regression tests. Filtered index handling in charmbracelet#632 and charmbracelet#638 remains outside this change.
andrinoff
approved these changes
Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Return early for indices outside the backing list, preventing negative-index panics and preserving filters when an ignored removal has no matches.
Keep the bounds guard proposed in #932 separate from its cursor changes. Add positive, negative, and regression tests. Filtered index handling in #632 and #638 remains outside this change.
CONTRIBUTING.md.fix(list): ignore out-of-range removal indices
RemoveItempromises to ignore out-of-range indices, but a negative index currently panics. A past-end removal can also clear an active filter when it has no matches.Check the index against the backing item list before changing items, filter state or pagination. Invalid removals become no-ops, while valid removals retain their existing behavior.
The patch includes three separate tests:
On unpatched main, the negative-index regression panics and the empty-match-filter case fails. The positive and negative controls pass. Deliberately skipping all removals makes the positive test fail; resetting the filter on invalid removal makes the negative test fail.
Closed, unmerged PR #932 proposed the same three-line bounds guard alongside changes to cursor positioning after valid removals. The guard itself is identical here. This PR isolates that safety fix and adds separate positive, negative and regression tests, deliberate-break checks, and the validation below, so it can be reviewed independently of the cursor changes.
Open PR #638 targets the mismatch between filtered and backing-list indices described in issue #632. That work determines which item a valid filtered removal should delete. This guard handles invalid backing-list indices before any state changes: it prevents the negative-index panic and keeps an ignored removal from clearing an empty-match filter.
Both reproductions from #632 still fail with this patch: removing by filtered index can delete a different backing item, and removing by backing index can leave a deleted item visible in the filtered list. This PR therefore does not close #632 or replace #638. Its contribution is a small, independently tested bounds fix; valid-removal indexing and cursor behavior remain unchanged.
Validation on main
1deada954e6e, Go 1.26.10:-count=4 -cpu=1,4; the new tests also pass 20 race repetitions.Cross-target binaries were compiled rather than executed. These are local checks; remote CI remains to be confirmed.
disclosure: i use ai, me and claude are buddies. this came up when working on my own harness, i root-caused it withclaude, claude wrote the patch, ir eviewed the patch, i asked codex to review the patch, and qwen said that i have great taste in bikes. lmk if you need anything changed; i think this is actually a good pr because the scope is very (very) narrow despite it touching/interacting with several others.