Skip to content

feat(tui): use Ctrl+F for fullscreen search and add /find command - #5466

Open
Grapedge wants to merge 9 commits into
mainfrom
fullscreen-ctrl-f
Open

Grapedge wants to merge 9 commits into
mainfrom
fullscreen-ctrl-f

Conversation

@Grapedge

@Grapedge Grapedge commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Screenshots / Recordings

全屏搜索框底栏文案(VirtualTerminal 78×6 渲染,关注右下角导航提示)

改动前改动后
alpha result
beta line                                    ┌──────────────────────────────┐
alpha second                                 │ alpha                    1/2 │
                                             └──── ↑ Shift+Enter · ↓ Enter ─┘
alpha result
beta line                                    ┌──────────────────────────────┐
alpha second                                 │ alpha                    1/2 │
                                             └──────── ↑ Previous · ↓ Next ─┘

全屏 /find 补全与 /help 面板(真实全屏 CLI 终端输出片段)

输入 /fi 时仅全屏模式列出 /find [query]:

 │   → find               [query] — Search the conversation
 │     settings (config)  Open TUI settings

全屏 /help 面板在快捷键与命令列表中分别显示 Ctrl-F 与 /find(普通模式均不显示):

   Keyboard shortcuts
     Shift-Tab             Toggle plan mode
     Ctrl-F                Search conversation
     Ctrl-G                Edit in external editor ($VISUAL / $EDITOR)
     Ctrl-O                Toggle tool output / compaction summary expansion
     Ctrl-S                Steer — inject a follow-up during streaming
     /feedback (/bug)                    Send feedback to make Kimi Code better
     /find                               Search the conversation
     /fork                               Fork the current session into a copy without switching to it
     /goal                               Start or manage an autonomous goal

Requirement or Bug

全屏模式此前只将对话搜索绑定在 Ctrl+Shift+F,容易被 Windows Terminal 等终端默认占用,在非 Kitty 协议终端里也无法与 Ctrl+F 区分。

本 PR 将全屏对话搜索默认快捷键改为全平台统一的 Ctrl+F(保留 Ctrl+Shift+F),为搜索结果跳转增加方向键 ↑ / ↓ 与 ↑ Previous · ↓ Next 标签,新增仅全屏可见的 /find [query] 命令,并同步修复搜索框打开时点击底部输入框仍被抢回焦点,以及输入带参数提示的斜杠命令(如 /find)时光标与输入法位置错位的问题。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路

直接在 packages/pi-tui 的 TUI_KEYBINDINGS 中更新全屏搜索默认键位,保持 getKeybindings() 作为所有组件唯一的键位真源;普通模式(TuiMainScreen)不消费 tui.altScreen.*,原有 Ctrl+F 光标右移不受影响。在 TuiAltScreen 上新增幂等的 openSearch(query?) 入口、快捷键让位守卫以及“非滚轮鼠标焦点切出搜索框时自动关闭搜索”的逻辑,同时在 keys.ts 中对称修复 Kitty 协议下 Caps Lock + 修饰键的大写字母匹配。在 apps/kimi-code 中用必填的 tuiMode 收口斜杠命令可见性与解析路径,并在 CustomEditor 中统一光标标记与可见宽度计算逻辑以修复参数提示下的光标和输入法定位。

结构图

flowchart LR
    A["TUI_KEYBINDINGS 默认键位<br/>packages/pi-tui/src/keybindings.ts"] --> B["TuiAltScreen<br/>openSearch / 快捷键让位 / 鼠标切焦点关闭搜索"]
    A --> C["AltScreenSearchComponent<br/>setQuery / ↑ Previous · ↓ Next"]
    D["keys.ts<br/>Kitty Caps Lock 修饰键归一化"] --> B
    E["斜杠命令注册表<br/>commands/registry.ts"] --> F["统一可见性过滤<br/>isSlashCommandVisible(tuiMode)"]
    F --> G["补全与 /help<br/>kimi-tui.ts / help-panel.ts"]
    F --> H["统一输入解析<br/>resolveHostUserInput"]
    H --> I["/find 命令分发<br/>commands/dispatch.ts"]
    I --> B
    J["CustomEditor<br/>共享光标锚点与可见宽度注入"] --> K["argumentHint / promptPrediction<br/>保留 CURSOR_MARKER 与行宽"]
Loading

键位默认值留在 TUI_KEYBINDINGS 单一真源里,避免应用层局部覆盖与组件内 getKeybindings() 分裂。斜杠命令可见性通过必填 tuiMode 收敛在 registry.ts 与 resolveHostUserInput,补全、/help 与提交解析共用同一套判断。

关键决策

决策 选择 没选 理由
全屏搜索默认键位归属 直接更新 pi-tui 的 TUI_KEYBINDINGS 在 TuiAltScreenOptions 增加实例级 keybindings 覆盖 pi-tui 内有 7 个组件(含搜索框内的 Input)读取 getKeybindings(),只在 TuiAltScreen 传实例键位会造成同一套 UI 读两份键位源;普通模式不读取 tui.altScreen.*,直接改 TUI_KEYBINDINGS 即可隔离
搜索框打开时点击底部输入框 非滚轮鼠标将焦点切到搜索框外时自动关闭搜索再转移焦点 保留搜索框打开并仅调用 setFocus(editor) TuiBase.showOverlay 通过 overlayFocusRestore 维持浮层焦点,只切焦点不关搜索会在下一次按键时把输入抢回搜索框;自动关闭搜索符合直觉,同时滚轮、框内点击与划词复制均保持搜索打开
普通模式下 /find 的表现 完全隐藏并透传为普通输入或同名 skill 显示命令并在执行时报错提示仅限全屏 普通模式用户不需要感知全屏专属能力,也不能抢占同名自定义 skill
预填查询光标位置 新增通用 Input.getCursor() / Input.setCursor(position) 并在 setQuery() 后置尾 修改 Input.setValue() 默认把光标放末尾,或只加特化的 moveCursorToEnd() 既有单测锁定了 Input.setValue() 光标归零的契约,而 getCursor() / setCursor(position) 与 getValue() / setValue() 对称且可用于任意光标位置读写
快捷键让位与 Kitty Caps Lock 兼容 在 TuiAltScreen 让位给聚焦的非搜索 capturing overlay 和无 ScrollView 布局;在 keys.ts 归一化 Caps Lock + 任意非锁修饰键的 A–Z 无条件拦截 Ctrl+F 或仅对 Ctrl 做特判 保护全屏接管视图(审批预览、任务查看器)和弹窗快捷键,并统一覆盖 Ctrl/Alt/Super 组合键
参数提示光标与宽度修复 在 custom-editor.ts 将 stripNonVisibleSequences 扩展跳过 APC 序列,并抽出 findCursorAnchor / injectTextAfterCursor 供 injectArgumentHint 与 injectPromptPrediction 共用 仅在 injectArgumentHint 中复制粘贴补丁 原 injectArgumentHint 还在查找旧版 CURSOR_BLOCK 并按原始字符串长度补空格,导致截掉 CURSOR_MARKER 与假光标并撑爆行宽;统一后两处共用同一套逻辑

阅读指南

  1. packages/pi-tui/src/keybindings.ts 与 packages/pi-tui/src/keys.ts:全屏搜索默认键位更新,以及 Kitty Caps Lock 修饰键大写字母归一化。
  2. packages/pi-tui/src/tui-alt-screen.ts、packages/pi-tui/src/alt-screen-search.ts、packages/pi-tui/src/components/input.ts:幂等 openSearch(query?)、浮层与无 ScrollView 布局的快捷键让位、非滚轮切焦点关闭搜索、↑ Previous · ↓ Next 标签与纯空白查询修复、Input.getCursor() / Input.setCursor(position)。
  3. apps/kimi-code/src/tui/commands/registry.ts、apps/kimi-code/src/tui/commands/resolve.ts、apps/kimi-code/src/tui/commands/dispatch.ts:/find 注册、visible(context) 可见性过滤、必填 tuiMode 的 resolveHostUserInput 统一解析与命令分发。
  4. apps/kimi-code/src/tui/components/editor/custom-editor.ts:APC 安全的 stripNonVisibleSequences,以及 injectArgumentHint / injectPromptPrediction 共享的光标锚点与可见宽度注入。
  5. apps/kimi-code/src/tui/components/dialogs/help-panel.ts 与 apps/kimi-code/src/tui/kimi-tui.ts:全屏 /help 快捷键展示与命令列表接线。

可略读:packages/pi-tui/UPSTREAM.md(fork 意图卡片)、docs/(四处参考表增补行)、.changeset/ 以及各测试文件。

Behavior Changes and Affected Users

行为 改动前 改动后 依赖旧行为的人群 退路
全屏模式下输入框按 Ctrl+F 在输入框中向右移动光标(与 → 相同) 打开或关闭全屏对话搜索框(保留 Ctrl+Shift+F) 启用全屏模式且习惯 Emacs/Readline Ctrl+F 右移的 TUI 用户 使用 → 右移光标,或切回普通模式(regular)保留原有 Ctrl+F 光标右移
全屏搜索框内按 ↑ / ↓ 及底栏标签 ↑ / ↓ 不切换匹配;底栏显示 ↑ Shift+Enter · ↓ Enter ↑ / ↓ 跳转上一处/下一处匹配(保留 Shift+Enter/Enter/Ctrl+Shift+G/Ctrl+G);底栏显示 ↑ Previous · ↓ Next(窄屏退化为 ↑ ↓) 依赖搜索框旧快捷键的 TUI 用户 原有 Enter / Shift+Enter / Ctrl+G / Ctrl+Shift+G 全部保留
搜索框打开时点击底部输入框或其他可聚焦组件 搜索框保持打开,下一次按键会被 overlayFocusRestore 抢回搜索框 非滚轮鼠标将焦点切到搜索框外时关闭搜索并将输入焦点交给目标组件;滚轮滚动、搜索框内点击与划词复制保持搜索打开 依赖“先点底部输入框但继续往搜索框打字”的极少数场景 点击搜索框内部区域继续在搜索框输入
全屏模式下输入 /find 或 /find <query> 无此内置命令,按普通消息或同名 skill 发送 打开并聚焦搜索框;带参数时预填单行查询词并将光标置于末尾,流式与压缩期间均可用 全屏模式下建有同名自定义 /find skill 的 TUI 用户 使用 /skill:find 显式调用同名 skill
普通模式(regular)下 Ctrl+F、/find 与 /help Ctrl+F 右移光标;无 /find;/help 不含 Ctrl-F 行为不变;普通模式 TuiMainScreen 不读取 tui.altScreen.*,且斜杠命令解析按必填 tuiMode 过滤掉 /find,Ctrl+F 与同名 skill 均走原路径 普通模式 TUI 用户、依赖普通模式同名 /find skill 的用户 无需退路(保持不变)
全屏下接管视图(无 ScrollView)及 pi-tui 聚焦的 capturing overlay 中按 Ctrl+F 透传给接管视图翻页或聚焦 overlay 处理 仍透传给聚焦的非搜索 pi-tui overlay 或无 ScrollView 的接管视图,不被搜索拦截(主布局内嵌挂载的面板如 /help、/model 仍保留主 ScrollView) 全屏 TUI 下使用审批预览(Ctrl+E)与 /tasks 查看器的用户 无需退路(保持不变)
输入带参数提示的斜杠命令(如 /find)时的光标与输入法定位 injectArgumentHint 截断 CURSOR_MARKER 与假光标并导致行宽溢出 保留 CURSOR_MARKER 与假光标并按 visibleWidth 对齐行宽,光标显示与中文输入法候选框定位恢复正常 所有使用带 argumentHint 内置斜杠命令的 TUI 用户 无需退路(缺陷修复)
Kitty 键盘协议开启 Caps Lock 时按带修饰键的大写字母 未归一化大写码点,pi-tui 键位匹配失败 keys.ts 将 Caps Lock + 任意非锁修饰键(Ctrl/Alt/Super/Shift)的 A–Z 归一化为小写键位,无修饰 Caps Lock 大写输入不受影响 使用 Kitty 协议终端并开启 Caps Lock 的 TUI 用户 无需退路(缺陷修复)
@moonshot-ai/pi-tui 默认全屏搜索键位与 API tui.altScreen.search 默认 ctrl+shift+f,searchNext/searchPrevious 默认不含 down/up;无 openSearch、getCursor/setCursor;纯空白查询显示 No matches 默认键位更新为 ["ctrl+f", "ctrl+shift+f"] 与 down/up 优先;新增 openSearch(query?) 与 Input.getCursor() / Input.setCursor(position);纯空白查询不显示 No matches 直接消费 @moonshot-ai/pi-tui 并依赖旧默认键位的调用方 通过 setKeybindings() 覆盖回旧键位

受影响模块与测试覆盖

  • packages/pi-tui:keybindings.test.ts、input.test.ts、keys.test.ts、tui-alt-screen.test.ts 覆盖默认键位更新、自定义 setKeybindings 覆盖与反转标签、openSearch 幂等/预填清洗/无 ScrollView 守卫、↑ Previous · ↓ Next 与窄屏退化、纯空白查询、聚焦非搜索浮层与无 ScrollView 接管视图透传、点击编辑器关闭搜索且滚轮/框内点击/划词不关闭搜索、Kitty Caps Lock 修饰键匹配。
  • apps/kimi-code:create-tui-state.test.ts、commands/find.test.ts、commands/registry.test.ts、commands/resolve.test.ts、components/editor/custom-editor.test.ts、components/panels/help-panel.test.ts、controllers/editor-keyboard.test.ts 覆盖全屏 Ctrl+F/Ctrl+Shift+F/↑/↓、普通模式 Ctrl+F 光标右移保留、接管视图透传 Ctrl+F、Caps Lock Ctrl+F、/find 全屏执行与普通模式隐藏(含同名 skill 透传)、流式与压缩期间可用、argumentHint 光标标记与行宽保持、全屏与普通模式 /help 差异。
  • docs:中英文 reference/keyboard.md 与 reference/slash-commands.md 同步增补。
  • 验证平台:macOS(Node v24.15.0)完成单测、类型检查、pnpm lint、check:duplication 以及真实全屏与普通模式 CLI 端到端交互验证;Linux 由 CI 覆盖(CI/build、CI/lint、CI/typecheck、CI/test (1..5)、CI/test-standalone-suites);Windows 未验证(本机为 macOS,且本次 PR 中 CI/test-windows 按工作流过滤条件被跳过)。
本地验证详情(HEAD acbf61c)
  • pnpm --filter @moonshot-ai/pi-tui test:1250 通过,0 失败,1 跳过(既有)。
  • pnpm exec tsc -p packages/pi-tui/tsconfig.json --noEmit 与 pnpm exec tsc -p apps/kimi-code/tsconfig.json --noEmit:通过。
  • pnpm exec vitest run --reporter=agent apps/kimi-code/test/tui/components/editor/custom-editor.test.ts apps/kimi-code/test/tui/create-tui-state.test.ts apps/kimi-code/test/tui/commands apps/kimi-code/test/tui/components/panels/help-panel.test.ts apps/kimi-code/test/tui/controllers/editor-keyboard.test.ts:29 个测试文件、564 个用例全部通过。
  • pnpm lint:全部检查通过,0 警告 0 错误。
  • pnpm run check:duplication 9c1c1451b25ce74e0762e9070c5682a889ea2d03:0 新增重复。
  • 真实终端端到端验证(全屏与普通模式 6/6):验证 Ctrl+F 打开搜索与 ↑ Previous · ↓ Next、↑/↓ 切换命中、Esc 关闭、/find 补全与 /find <query> 预填光标置末、全屏 /help 展示及普通模式完全隐藏。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: acbf61c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code Minor
@moonshot-ai/pi-tui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T12:56:47.859166Z acbf61c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@acbf61c
npx https://pkg.pr.new/@moonshot-ai/kimi-code@acbf61c

commit: acbf61c

…igation labels

Allow TuiAltScreen instances to override viewport and search keybindings without mutating the global singleton, add idempotent TuiAltScreen.openSearch(query?) with Input.moveCursorToEnd(), show semantic arrow navigation labels (↑ Previous / ↓ Next), defer search shortcuts to focused non-search overlays and non-scroll layout roots, and normalize Kitty Caps Lock + Ctrl letter sequences.
…command

Bind fullscreen transcript search to Ctrl+F (retaining Ctrl+Shift+F) and match navigation to ↑/↓ via per-instance keybindings, add fullscreen-only /find [query] command hidden in regular mode, unify host slash-command resolution with runtime tuiMode, and show Ctrl-F in fullscreen /help.
…esets

Document Ctrl-F and /find [<query>] in English and Chinese reference pages and add changesets for @moonshot-ai/pi-tui and @moonshot-ai/kimi-code.
…mponent

Close active transcript search before transferring mouse focus to a component outside the search overlay so keyboard input goes directly to the clicked target instead of being reclaimed by overlay focus restore, while keeping scroll, selection, and search-box clicks open.
…ints

Update CustomEditor argument hint injection to anchor after FAKE_CURSOR_END and measure trailing padding with visibleWidth so hardware cursor and IME positioning remain intact and lines do not overflow; skip APC cursor markers during slash token highlighting.
@Grapedge

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acbf61c990

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

},
"tui.altScreen.search": {
defaultKeys: "ctrl+shift+f",
defaultKeys: ["ctrl+f", "ctrl+shift+f"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep pi-tui's upstream search defaults unchanged

Changing the published library-wide default to include Ctrl+F affects every direct @moonshot-ai/pi-tui alternate-screen consumer: a key that previously reached the focused editor and moved its cursor right is now intercepted to open search unless the consumer proactively overrides the bindings. Keep the upstream default and enable the Kimi-specific binding through an application-owned opt-in or default-disabled extension.

AGENTS.md reference: packages/pi-tui/AGENTS.md:L13-L17

Useful? React with 👍 / 👎.

const focusTarget = this.resolveMouseFocusTarget(result.focusTarget ?? result.target.component);
const focusChanged = result.focus === true && this.getFocusedComponent() !== focusTarget;
if (result.focus) this.setFocus(focusTarget);
const shouldFocus = result.focus === true && event.type !== "wheel";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Honor focus requests from wheel handlers outside search

When any TuiAltScreen component returns { focus: true } from a wheel handler, this condition now discards the request even when transcript search is not active. TuiMouseEventResult.focus promises keyboard focus without excluding wheel events, and the previous implementation always called setFocus, so wheel-to-focus components can scroll while subsequent keys remain routed to the previously focused component. Limit the wheel suppression to the active-search case rather than changing mouse focus semantics globally.

AGENTS.md reference: packages/pi-tui/AGENTS.md:L13-L17

Useful? React with 👍 / 👎.

textWidth: number,
): string {
const remaining = Math.max(0, visibleWidth(line.slice(insertAt)) - textWidth);
return line.slice(0, insertAt) + styledText + ' '.repeat(remaining);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve text following an inline cursor

When a user moves the caret left while the input is still a hint-bearing command such as /find , insertAt is immediately after the fake cursor, so this return replaces every character after the caret with the hint and padding. The underlying editor value still contains those characters, leaving the displayed command inconsistent with what will be submitted; preserve the existing suffix or only inject the hint when the caret is at the command's end.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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