Skip to content

fix: wrap keyboard selection in the @ file picker - #769

Open
killersteps wants to merge 1 commit into
agegr:mainfrom
killersteps:fix/at-file-menu-wrap
Open

fix: wrap keyboard selection in the @ file picker#769
killersteps wants to merge 1 commit into
agegr:mainfrom
killersteps:fix/at-file-menu-wrap

Conversation

@killersteps

@killersteps killersteps commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Problem

ArrowDown on the @ file picker clamps at the last match. Once the highlight is on the bottom row, another Down does nothing, so you cannot wrap back to the first file. ArrowUp has the same clamp at the top.

The list is already scrollable and already calls scrollIntoView on the active row. The missing piece is cycling the index.

Solution

Wrap the active index in both directions:

  • Down on the last row → first row
  • Up on the first row → last row
  • Empty list stays at 0

Existing scrollIntoView({ block: "nearest" }) then brings the opposite end into the visible list.

Tests

  • Handler-level: Down from the last of 3 matches goes to 0; Up from 0 goes to 2.
  • cycleListIndex unit cases for both directions, a single-item list, and an empty list.

node --experimental-strip-types --test components/ChatInput.test.mjs passes.


问题

@ 文件列表里按 ↓ 到最后一项会被夹住。高亮已经在最后一行时,再按 ↓ 没有反应,没法回到第一项。↑ 在第一项同样被夹住。

列表本身可以滚动,高亮行也已经会 scrollIntoView。缺的只是下标循环。

解决方案

两个方向都循环高亮下标:

  • 最后一项再按 ↓ → 第一项
  • 第一项再按 ↑ → 最后一项
  • 空列表保持 0

现有的 scrollIntoView({ block: "nearest" }) 会把另一端滚进可见区域。

测试

  • 按键处理:3 条匹配时,最后一项再 ↓ 得到 0;第 0 项再 ↑ 得到 2。
  • cycleListIndex 覆盖双向循环、只有一项、空列表。

node --experimental-strip-types --test components/ChatInput.test.mjs 通过。

ArrowDown at the last match and ArrowUp at the first match currently
clamp, so the list cannot be cycled. Wrap the active index so the
highlighted row returns to the other end, matching typical picker UX.
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.

1 participant