Skip to content

fix(quick-tools): navigate results with Up/Down while input is focused - #7489

Merged
M4n5ter merged 3 commits into
apache:mainfrom
MicroGery:fix/quick-tools-arrow-navigation
Dec 1, 2026
Merged

M4n5ter merged 3 commits into
apache:mainfrom
MicroGery:fix/quick-tools-arrow-navigation

Conversation

@MicroGery

@MicroGery MicroGery commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • The new regression failed against the previous implementation: after moving back to the first result and pressing Up, the input remained Alpha instead of recalling remembered.
  • All 4 related headless UI tests passed after the fix: both tests::launcher_ tests and both tests::quick_ tests. They exercise the real Launcher component with macOS native focus-scope behavior; this is not a manual AppKit UI test.
  • All 22 tests in products/maka/workbench/tests/quick-tools.test.mjs passed.
  • Generated the UI declarations with 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, and git diff --check passed. The commit hooks passed with the pinned Biome 2.6.3.
  • GitHub PR Check passed at 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 large warning.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

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

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass (Rust compilation/tests on Mac mini)

Does this PR entail a breaking change or persisted-data migration?

  • Yes
  • No

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

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.
@github-actions github-actions Bot added the effort/S Under 100 readable lines label Dec 1, 2026
M4n5ter
M4n5ter previously requested changes Dec 1, 2026

@M4n5ter M4n5ter left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Up at row 0 to enter search history (and Down to restore the draft or move down through results—historyAtSelection already returns null for Down when idle) is intentional and asserted by both products/maka/workbench/tests/quick-tools.test.mjs and launcher_filters_selected_actions_and_restores_the_query in products/maka/workbench/src/lib.rs. With this change, launcher_filters_selected_actions_and_restores_the_query fails (fast PR checks didn't run the maka-workbench Rust suite).
  • The empty-list fallback is unreachable: When rows().length === 0, selectedRowIndex([], ...) in products/maka/workbench/app/quick-results.ts returns -1. In products/maka/workbench/app/quick-input-history.ts:
    if (cursor.index < 0 && (selected < 0 || direction === 1)) return null;
    Since cursor.index starts at -1 and selected === -1, historyAtSelection returns null here as well. Combined with the rows().length short-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::matched in third-party/nsh/crates/nsh-platform-macos/src/keymap.rs resolves window and root from event.window(surface.mtm), but computes the within focus path via crate::input::focus_path(surface) (line 172).
  • focus_path(surface) in third-party/nsh/crates/nsh-platform-macos/src/input.rs (line 1336) ignores the event window and queries app_key_window(surface.mtm) (NSApplication.sharedApplication.keyWindow()), which can be nil when the app is inactive with a NonactivatingPanel.
  • Whenever focus_path is empty, every within: node binding in the popup fails together—not just up/down, but also backspace (leave tool), mod+enter, mod+,, mod+1..9, and up/down inside the Cmd+K action menu. Dropping within: node only on up/down leaves all sibling bindings broken and widens arrow-key capture to the entire popup window.

Suggested next steps

  1. 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, and Cmd+K menu Up/Down fail under the same condition.
  2. If within matching is failing in a non-activating popup, fix it at the root in nsh-platform-macos by computing focus_path against the event's (&root, &window) (mirroring nsh-platform-linux/src/keymap.rs and the explicit window-root approach from #7454), with a native AppKit regression test.
  3. Revert the rows().length change in navigate() and verify with:
    • cargo test -p maka-workbench launcher_filters_selected_actions_and_restores_the_query
    • node --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 去掉既无法修复同窗其他快捷键,又把方向键劫持扩大到了整个弹窗。

建议下一步

  1. 补充确切的复现条件(例如:其他 App 在前台通过全局快捷键呼出 vs. Maka 在前台时),并确认同条件下 Cmd+Enter、Cmd+,、Cmd+1 以及 Cmd+K 菜单里的 Up/Down 是否一并失效。
  2. 如果确认是非激活弹窗下 within 失效,请在 nsh-platform-macos 根因层修复——在 keymap::matched 中把事件对应的 (&root, &window) 显式传给 focus_path(对齐 nsh-platform-linux/src/keymap.rs 和 #7454 的做法),并补一条原生 AppKit 回归测试。
  3. 撤回 navigate() 中 rows().length 的短路改动,并跑通:
    • cargo test -p maka-workbench launcher_filters_selected_actions_and_restores_the_query
    • node --test products/maka/workbench/tests/quick-tools.test.mjs

@M4n5ter
M4n5ter dismissed their stale review December 1, 2026 06:37

Switching to a non-blocking comment review.

MicroGery and others added 2 commits December 1, 2026 15:31
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`).

@M4n5ter M4n5ter left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@M4n5ter
M4n5ter merged commit fff1643 into apache:main Dec 1, 2026
1 check passed
jay23606 added a commit to jay23606/maka that referenced this pull request Dec 1, 2026
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/S Under 100 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants