Skip to content

feat(tui):改进 TAB 模式切换并稳定斜杠/粘贴输入行为#562

Merged
phantom5099 merged 4 commits into1024XEngineer:mainfrom
creatang:main
May 5, 2026
Merged

feat(tui):改进 TAB 模式切换并稳定斜杠/粘贴输入行为#562
phantom5099 merged 4 commits into1024XEngineer:mainfrom
creatang:main

Conversation

@creatang
Copy link
Copy Markdown
Collaborator

@creatang creatang commented May 5, 2026

背景

这组改动主要聚焦 TUI 输入交互的一致性和可预期性,覆盖三类问题:

  1. slash 多词补全异常,以及已废弃快捷能力的清理。
  2. TAB 切换 plan/build 模式能力落地,并修复输入态下无法切换的问题。
  3. 粘贴启发式导致的误判与长文本粘贴重复 token 问题修复。

改动概览

1) slash 补全与废弃能力清理

  • 修复了带空格的 slash 指令在 TAB 补全时的替换范围问题(避免多词命令补全后残留异常字符)。
  • 删除冗余/废弃交互:
    • Ctrl+O 文件浏览入口移除。
    • 面板焦点切换相关能力移除(后续由 TAB 承接模式切换)。

对应 commit: 2e387dac

2) 新增 TAB 切换 plan/build(含后端透传)

  • 新增 TAB 在 TUI 中切换 plan/build 的能力。
  • 增加模式状态管理(UI state + run context)。
  • 在提交运行时将 mode 透传到 gateway/runtime。
  • header 中显示当前 mode,并与主题强调色联动。

对应 commit: 0d224144

3) 修复“输入时无法切换 plan/build”

  • 调整 TAB 事件优先级:保留“补全优先”,移除“输入态 Tab 插入制表符”的抢占。
  • 现在在正常输入状态下也可以切换 plan/build(有补全候选时仍优先补全)。

对应 commit: 1ea96dfd

4) 粘贴行为修复(误判与长文本重复 token)

  • 修复单字输入与剪贴板前缀重叠时的误判问题(避免普通输入被当作粘贴流)。
  • 修复长文本粘贴在分片场景下重复注入 [paste N LINE] token 的问题:
    • 进入 paste transaction 后持续吸收分片,统一 flush,避免同一段内容被拆分多次摘要。
  • 补充对应回归测试用例。

对应 commit: 1151ea6e

影响与兼容性

  • TAB 在输入框中的语义已调整为“补全优先,其次模式切换”,不再用于插入制表符。
  • 粘贴启发式更保守,优先保证“普通输入不误判”,同时维持长文本粘贴摘要能力。

测试

已执行:

  • go test ./internal/tui/...

关键用例覆盖:

  • slash 多词补全稳定性。
  • 输入态 TAB 模式切换。
  • 长文本粘贴摘要去重。
  • 单字普通输入不被剪贴板前缀误判。

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

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

Reviewed the TUI mode-switching, slash completion, and paste-handling changes. I found 2 noteworthy issues; I did not find separate performance or security-only findings beyond these.

return strings.ContainsRune(chunk, '\n') || strings.ContainsRune(chunk, '\r') || strings.ContainsRune(chunk, '\t')
// Once a paste transaction starts, keep absorbing rune chunks until debounce flush.
// This avoids fragmenting one long paste into repeated summary tokens.
return true
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pasteTxnActive now makes every subsequent non-Paste rune event part of the paste transaction until the debounce flush fires. That widens a false positive into a real input regression: an IME commit or any other multi-rune key event can start the transaction, and then normal typing typed immediately after it gets swallowed and summarized as paste content. The previous logic still required the follow-up chunks to look paste-like; I think that guard needs to stay in some form, plus a regression test for "paste starts, then the user types normally before flush".

@@ -112,8 +97,7 @@ func (k keyMap) ShortHelp() []key.Binding {
func (k keyMap) FullHelp() [][]key.Binding {
return [][]key.Binding{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR turns Tab into the primary plan/build toggle, but that shortcut is still absent from the help surfaces (ShortHelp/FullHelp, and the startup quick actions are unchanged too). As shipped, the feature is only discoverable if someone already knows it exists, so the user-facing help is now out of sync with the behavior.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

❌ Patch coverage is 90.62500% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/tui/core/app/update.go 76.92% 4 Missing and 2 partials ⚠️
internal/tui/core/app/command_menu.go 76.92% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@phantom5099 phantom5099 merged commit 2b6a7a7 into 1024XEngineer:main May 5, 2026
3 checks passed
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.

2 participants