fix(chat): keep the slash command selection visible and valid on long or filtered lists - #499
Merged
mbektas merged 3 commits intoSep 24, 2026
Conversation
The suggestion popover scrolls when it holds more commands than fit, but the arrow keys only moved the selection, so it walked out of view and the rest of the list was reachable only with the mouse wheel. Scroll the selected row into view with block: nearest whenever the selection changes, including when it wraps from the first row to the last. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ring The selected index is state that outlives the list it was chosen from. Arrow down to row 12 of 30, then type a character that narrows the list to 3, and the index points past the end: no row is highlighted, and Enter applies an undefined suggestion, which throws in applyPrefixSuggestion and swallows the keypress. Reset the selection to the first row whenever the filter changes, and read it through activeSuggestionIndex, which falls back to the first row for any index that no longer points at one, so no other path that shrinks the list can leave it dangling. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mbektas
approved these changes
Sep 22, 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.
Summary
Fixes keyboard navigation of the slash /
@command popover on long or filtered lists.Closes #498
Problem
applyPrefixSuggestion(undefined). That throws (Cannot read properties of undefined (reading 'startsWith')) and swallows the keypress. This is the same class of problem as the "Enter with an unmatched@or/" fix (fix(chat): let Enter send a message that starts with an unmatched @ or / #464).Solution
scrollSelectedSuggestionIntoViewscrolls the selected row into view withblock: 'nearest'whenever the selection changes, including on wrap-around.nearestscrolls by the smallest amount and does nothing when the row is already visible.filterPrefixSuggestionsresets the selection to the first row, since a narrowed list is a different list.activeSuggestionIndex(selected, count)returns the index if it still points at a row and 0 otherwise. Enter, Tab, both arrow keys, the highlight class and the scroll effect all read the index through it, so no other path that shrinks the list can leave it dangling.Two commits: the scroll fix, then the stale-index fix.
How to test
I checked this by hand in JupyterLab, on
mainand on this branch, with a small test extension that adds a participant@manywith 30 commands, so the popover has 33 rows in Ask mode. The full extension source and steps are in #498. In short:/, press ArrowDown 20+ times. Onmainthe highlight leaves the visible list; on this branch it follows the selection, including the wrap from last to first and back./, ArrowDown about 20 times, typecmd30, press Enter. Onmainnothing is highlighted, Enter does nothing and the console shows theTypeError. On this branch the single match is highlighted and Enter completes it.Both symptoms reproduce on
mainand are resolved on this branch.Testing
tests/ts/chat-prefix-suggestions.test.tscoversscrollSelectedSuggestionIntoView(only the selected row is scrolled, wrap-around, missing popover / out-of-range index / noscrollIntoView) andactiveSuggestionIndex(valid, out-of-range, negative and empty lists, and the exact narrowed-list scenario). If the helper returned the raw index, 3 of the new tests fail.base.csslayout: with the fix, no selected row left the popover in any of the sizes tried (0 rows off-screen, against 26, 36 and 4 without it).jlpm jest(583 passed),jlpm tsc --noEmit,jlpm lint:checkandpytest tests/(2221 passed) are clean.Not covered by an automated test: the reset in
filterPrefixSuggestionsitself, because there is no component test harness forChatSidebar. The helper is the safety net for it, and the manual test above exercises the reset.Not checked: Firefox, macOS, and Claude or ACP mode. Their command lists are built from a different source, but they use the same popover.
🤖 Generated with Claude Code