Repository navigation
fix(quick-tools): navigate results with Up/Down while input is focused - #7489
Conversation
The Quick Tools launcher only navigated the result list with Up/Down when the search field did not have focus. When the field was focused, the arrows were consumed by the input (or left to native caret motion), so users could not keyboard-cycle the candidates. Change the arrow bindings to fire even while editing and always move the result list first. Input-history cycling is kept as a fallback only when there are no result rows. Focus is returned to the input after each move so typing can continue.
There was a problem hiding this comment.
English
A couple of issues worth addressing:
1. navigate() breaks existing input-history behavior/tests and makes historyAtSelection dead code
In products/maka/workbench/app/QuickLauncher.tsx (lines 624–637):
const next =
props.scope() || rows().length
? null
: historyAtSelection(props.history(), index, cursor, query(), direction);- Breaks existing contract and tests: Pressing
Upat row 0 to enter search history (andDownto restore the draft or move down through results—historyAtSelectionalready returnsnullforDownwhen idle) is intentional and asserted by bothproducts/maka/workbench/tests/quick-tools.test.mjsandlauncher_filters_selected_actions_and_restores_the_queryinproducts/maka/workbench/src/lib.rs. With this change,launcher_filters_selected_actions_and_restores_the_queryfails (fast PR checks didn't run themaka-workbenchRust suite). - The empty-list fallback is unreachable: When
rows().length === 0,selectedRowIndex([], ...)inproducts/maka/workbench/app/quick-results.tsreturns-1. Inproducts/maka/workbench/app/quick-input-history.ts:Sinceif (cursor.index < 0 && (selected < 0 || direction === 1)) return null;
cursor.indexstarts at-1andselected === -1,historyAtSelectionreturnsnullhere as well. Combined with therows().lengthshort-circuit, input history can never be entered in any state.
2. Dropping within: node only works around a symptom and leaves sibling bindings broken
QuickLauncher.tsx already binds up and down with { when: 'always', within: node, repeat: true }, and those bindings already work when focus is inside the input in the workbench tests.
If Up/Down stop firing while the search input is focused on macOS—especially when summoning Quick Tools via the global shortcut while another app is frontmost—the likely root cause is in nsh-platform-macos rather than missing when: 'always' in QuickLauncher.tsx:
- QuickLauncher opens as a non-activating popup (
kind="popup" activate={false},NSWindowStyleMask::NonactivatingPanel). keymap::matchedinthird-party/nsh/crates/nsh-platform-macos/src/keymap.rsresolveswindowandrootfromevent.window(surface.mtm), but computes thewithinfocus path viacrate::input::focus_path(surface)(line 172).focus_path(surface)inthird-party/nsh/crates/nsh-platform-macos/src/input.rs(line 1336) ignores the event window and queriesapp_key_window(surface.mtm)(NSApplication.sharedApplication.keyWindow()), which can benilwhen the app is inactive with aNonactivatingPanel.- Whenever
focus_pathis empty, everywithin: nodebinding in the popup fails together—not justup/down, but alsobackspace(leave tool),mod+enter,mod+,,mod+1..9, andup/downinside theCmd+Kaction menu. Droppingwithin: nodeonly onup/downleaves all sibling bindings broken and widens arrow-key capture to the entire popup window.
Suggested next steps
- Confirm the exact reproduction steps (e.g., summoning Quick Tools while another app is active vs. while Maka is active) and check whether
Cmd+Enter,Cmd+,,Cmd+1, andCmd+KmenuUp/Downfail under the same condition. - If
withinmatching is failing in a non-activating popup, fix it at the root innsh-platform-macosby computingfocus_pathagainst the event's(&root, &window)(mirroringnsh-platform-linux/src/keymap.rsand the explicit window-root approach from #7454), with a native AppKit regression test. - Revert the
rows().lengthchange innavigate()and verify with:cargo test -p maka-workbench launcher_filters_selected_actions_and_restores_the_querynode --test products/maka/workbench/tests/quick-tools.test.mjs
简体中文
有两个问题建议确认和修改:
1. navigate() 的改动破坏了既有搜索历史契约与测试,且让 historyAtSelection 变成完全不可达的死代码
products/maka/workbench/app/QuickLauncher.tsx(第 624–637 行):
const next =
props.scope() || rows().length
? null
: historyAtSelection(props.history(), index, cursor, query(), direction);- 破坏既有行为与测试:在第一条结果(
selected === 0)按Up进入搜索历史、按Down恢复草稿(且未进入历史时按Down本就会返回null,不会阻碍列表向下移动)是有意设计,在products/maka/workbench/tests/quick-tools.test.mjs和products/maka/workbench/src/lib.rs的launcher_filters_selected_actions_and_restores_the_query中均有明确断言。当前改动会导致该 Rust 测试失败(PR Check 只跑了 fast check,未运行maka-workbench测试)。 - “结果为空时回退历史”同样跑不通:当
rows().length === 0时,products/maka/workbench/app/quick-results.ts里的selectedRowIndex([], ...)返回-1;而products/maka/workbench/app/quick-input-history.ts第 51 行是:初始if (cursor.index < 0 && (selected < 0 || direction === 1)) return null;
cursor.index === -1且selected === -1,同样会直接返回null。配合外层的rows().length短路,输入历史在任何状态下都无法进入。
2. 去掉 within: node 只是绕开表面症状,未修根因且会让同窗其他快捷键继续失效
原代码在 QuickLauncher.tsx 中本就为 up/down 绑定了 { when: 'always', within: node, repeat: true },在现有的 workbench 测试里也能在输入框聚焦时正常触发。
如果真机 macOS 上确实出现“搜索框聚焦时 Up/Down 失效、失焦后才可用”(尤其是别的 App 在前台时通过全局快捷键呼出 Quick Tools),根因更可能在 nsh-platform-macos 层,而不是 QuickLauncher.tsx 缺少 when: 'always':
- QuickLauncher 是非激活弹窗(
kind="popup" activate={false},对应NSWindowStyleMask::NonactivatingPanel)。 third-party/nsh/crates/nsh-platform-macos/src/keymap.rs的matched()从event.window(surface.mtm)解析出了当前弹窗的window和root,但第 172 行计算within路径时调用的却是crate::input::focus_path(surface)。third-party/nsh/crates/nsh-platform-macos/src/input.rs(第 1336 行)里的focus_path(surface)忽略了事件窗口,转而查询app_key_window(surface.mtm)(即NSApplication.sharedApplication.keyWindow()),在应用未激活但NonactivatingPanel接收按键时可能拿到nil,导致focus_path为空。- 一旦
focus_path为空,弹窗内所有依赖within: node的绑定都会一起失效——不只是up/down,还包括backspace(退出子工具)、mod+enter、mod+,、mod+1..9以及Cmd+K动作菜单里的up/down。仅把up/down的within: node去掉既无法修复同窗其他快捷键,又把方向键劫持扩大到了整个弹窗。
建议下一步
- 补充确切的复现条件(例如:其他 App 在前台通过全局快捷键呼出 vs. Maka 在前台时),并确认同条件下
Cmd+Enter、Cmd+,、Cmd+1以及Cmd+K菜单里的Up/Down是否一并失效。 - 如果确认是非激活弹窗下
within失效,请在nsh-platform-macos根因层修复——在keymap::matched中把事件对应的(&root, &window)显式传给focus_path(对齐nsh-platform-linux/src/keymap.rs和 #7454 的做法),并补一条原生 AppKit 回归测试。 - 撤回
navigate()中rows().length的短路改动,并跑通:cargo test -p maka-workbench launcher_filters_selected_actions_and_restores_the_querynode --test products/maka/workbench/tests/quick-tools.test.mjs
Switching to a non-blocking comment review.
Let the existing history boundary decide when arrows recall prior input. Keeping history behind an empty-results guard prevented the idle cursor from ever entering it. Add a real Launcher regression covering result selection, multiple unmatched history entries, draft restoration and typing after navigation. Move the history assertions out of the action-menu test and apply the formatter to the touched launcher file. Validated on Mac mini: the regression fails before the fix; four UI tests, 22 Quick Tools Node tests, generated UI type checks and formatting pass. Generated-by: Codex
…ivating popups Compute the `within` focus path in `keymap::matched` and `input::key` from the event's own `(&root, &window)` instead of `NSApplication.keyWindow`, and fall back to key `surface.windows` in `focus_path` when `NSApplication.keyWindow` is unset (such as a non-activating Quick Tools popup while the app is inactive). Reuse the computed focus path when dispatching `KeyCommand`, revert the `QuickLauncher.tsx` `within: node` workaround so all scoped popup bindings (arrows, Backspace, Cmd+Enter, Cmd+,, Cmd+1..9, and Cmd+K action search) keep working together, and add a native AppKit regression test (`popup_keymap.rs`).
There was a problem hiding this comment.
Moved the fix to the root cause in nsh-platform-macos (focus_path_in / key_window_root) so scoped within bindings resolve against the event's own window even when the app is inactive and NSApplication.keyWindow is unset. Reverted the QuickLauncher.tsx workaround, kept the launcher history regression test, and added a native AppKit popup_keymap regression test (failed before the fix, passed after). Verified locally: native popup_keymap + window_escape, maka-workbench launcher/quick suites, quick-tools.test.mjs, cargo check -p maka-desktop-shell, fmt, and ASF license checks.
… window (apache#7489) Resolve scoped (`within`) keymap focus paths in `nsh-platform-macos` against the event's own `(&root, &window)` in `keymap::matched` and `input::key`, and fall back to key `surface.windows` in `focus_path` when `NSApplication.keyWindow` is unset (e.g. a non-activating Quick Tools popup while the app is inactive). - Keeps all scoped Quick Tools bindings (Up/Down, Backspace, Cmd+Enter, Cmd+,, Cmd+1..9, and Cmd+K action search) working while the search input is focused, without weakening `within: node` in `QuickLauncher.tsx`. - Adds a native AppKit regression test (`popup_keymap.rs`) covering scoped Up/Down in an inactive non-activating popup and scope enforcement after focus leaves the input. - Adds a workbench regression test covering Launcher Up/Down result navigation, multi-entry unmatched history recall, draft restoration, and continued typing. Generated-by: Codex Co-authored-by: MicroGrey <changyuhang@outlook.com>
Summary
Keep Quick Tools result navigation active while the search input is focused, without disabling input-history recall. Up/Down use one launcher-level handler and return focus to the query after moving. At the first unscoped result, Up recalls prior input; Down walks back through history and restores the original draft. Tool-scoped searches retain result-only navigation.
The initial implementation gated history on an empty result list, but the history helper cannot start with no selected result. That made history unreachable. Restore the existing boundary rule and add a dedicated Launcher interaction regression that covers list selection, multiple historical queries with no matching rows, draft restoration, and typing after navigation. The existing action-menu test retains its action-specific checks.
Verification
Verified on Mac mini on December 1, 2026:
Alphainstead of recallingremembered.tests::launcher_tests and bothtests::quick_tests. They exercise the real Launcher component with macOS native focus-scope behavior; this is not a manual AppKit UI test.products/maka/workbench/tests/quick-tools.test.mjspassed.cargo run --locked -p maka-workbench --example ui_types, then typechecked the real UI sources and fixtures with TypeScript; passed after applying the repository's required dependency postinstall patches.cargo fmt --all -- --check, Biome formatting of both touched TSX files, andgit diff --checkpassed. The commit hooks passed with the pinned Biome 2.6.3.84206afb8e(run).The first compile ran out of runner disk space before executing tests. After cleaning unused build caches, compilation and the regression runs completed. macOS debug linking emits a non-fatal
__eh_frame section too largewarning.AI use
Codex assisted with the history-navigation fix, regression test and PR description. The follow-up commit includes
Generated-by: Codex; retain that trailer in the squash commit.Checklist
Does this PR entail a breaking change or persisted-data migration?
Does this PR entail a change in behavior?