fix: retain existing input text when selecting slash commands with optional details - #486
Merged
Merged
Conversation
…tional details
**问题**
在输入框中已有文字时,选择带有 "Add details(optional)" 的斜杠命令(非 immediate badge 类命令),输入框内容会被直接清空。期望已有文本应作为 details 保留。
**修复**
- `src/lib/message-input-logic.ts`
- `resolveItemSelection` 的 `set_badge` 分支现在计算 `newInputValue`,去掉 `/` 触发符和过滤文本,保留触发位置前后的用户输入内容
- `src/hooks/useSlashCommands.ts`
- `insertItem` 的 `set_badge` 分支使用 `result.newInputValue` 回填输入框,替代之前的硬编码 `setInputValue('')`
- `electron/main.ts`
- dev 模式端口支持 `PORT` 环境变量,避免与本地其他服务冲突
**影响范围**
仅影响 badge 类斜杠命令的输入框回填行为;immediate 命令(如 /clear)仍保持原有清空逻辑不变。
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>**补充修复** 在 #1 斜杠命令保留已有文本的修复基础上,进一步确保选择命令后光标自动定位到输入框尾部,而不是默认的首部。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@KevinYoung-Kw is attempting to deploy a commit to the op7418's projects Team on Vercel. A member of the Team first needs to authorize it. |
Uh oh!
There was an error while loading. Please reload this page.
Closed
op7418
commented
Apr 15, 2026
Owner
已合并 🎉 主逻辑修复很干净,splitAroundTrigger 抽成 helper 也顺手消除了 file_mention 那条路的重复代码。 注意到顺便带了一个 electron/main.ts 的改动(允许 PORT 环境变量覆盖 dev 默认 3000)——这和斜杠命令 bug 没直接关系,属于 drive-by scope,理想情况应该拆成独立 PR。不过改动本身是好的、也不冲突,我合一起了。下次如果有类似场景建议单独开 PR,评审时专注度更高。 感谢贡献,下次发版带上。 |
op7418 added a commit
that referenced
this pull request
Apr 15, 2026
Fixes: - cc-switch 切换 provider 被默默改路由 (#461/#478/#476/#457/#470/#474) - OpenAI OAuth 403/网络失败自动重试 (#464) - Electron 端口稳定化修复 localStorage 配置全丢 (#465/#466/#477) - v0.49.0+ 长对话 AI_MissingToolResultsError 回归 - Turbopack CJS↔ESM interop 导致 streamClaudeSdk is not a function - 内置 MCP 自动批准 (Memory/Widget/Notify 等 7 个) - Claude Code executable not found on Windows (SDK bundle 修复) - 切换会话后计时器归零 (#480/#484) - 选 slash 命令清空已输入文本 (#479/#486) - Skills 弹窗误触发路径 + 多选 + badge 去描述 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
youcho2 pushed a commit
to youcho2/CodePilot
that referenced
this pull request
Aug 11, 2026
…tional details (op7418#486) 斜杠命令清空已有输入框内容的问题。根因:resolveItemSelection 返回 set_badge 时没带 newInputValue,useSlashCommands 直接 setInputValue(''),导致触发位前后的用户输入被清空。 修法: 1. message-input-logic.ts: set_badge 分支计算 newInputValue(去掉 / 触发符和过滤文本,保留前后用户内容) 2. useSlashCommands.ts: 回填 newInputValue 并将光标定位到文本末尾 3. 附带:electron/main.ts dev 模式支持 PORT 环境变量覆盖(scope creep 但不冲突) Closesop7418#479. Co-Authored-By: Kevin Young <kevinyoung-kw@example>
youcho2 pushed a commit
to youcho2/CodePilot
that referenced
this pull request
Aug 11, 2026
Fixes: - cc-switch 切换 provider 被默默改路由 (op7418#461/op7418#478/op7418#476/op7418#457/op7418#470/op7418#474) - OpenAI OAuth 403/网络失败自动重试 (op7418#464) - Electron 端口稳定化修复 localStorage 配置全丢 (op7418#465/op7418#466/op7418#477) - v0.49.0+ 长对话 AI_MissingToolResultsError 回归 - Turbopack CJS↔ESM interop 导致 streamClaudeSdk is not a function - 内置 MCP 自动批准 (Memory/Widget/Notify 等 7 个) - Claude Code executable not found on Windows (SDK bundle 修复) - 切换会话后计时器归零 (op7418#480/op7418#484) - 选 slash 命令清空已输入文本 (op7418#479/op7418#486) - Skills 弹窗误触发路径 + 多选 + badge 去描述 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CodePilot 版本: v0.50.1
问题描述
在输入框中已经输入了一段文字后,如果选择带有 "Add details (optional)" 的斜杠命令(badge 类命令),输入框内的所有内容会被直接清空。期望已有文本应作为 details 内容保留下来。
根因
message-input-logic.ts的resolveItemSelection在返回action: 'set_badge'时没有带上newInputValue。useSlashCommands.ts的调用方直接硬编码了setInputValue(''),导致无论用户之前打了什么字都被清空。修复
src/lib/message-input-logic.ts— 在set_badge分支里计算newInputValue:去掉/触发符和过滤文本,保留触发位置前后的用户输入内容。src/hooks/useSlashCommands.ts— 用result.newInputValue回填输入框,并将光标自动定位到文本末尾,方便用户继续输入 details。immediate 命令(如
/clear、/help)的行为保持不变,不受影响。改动文件
src/lib/message-input-logic.tsset_badge分支计算并返回newInputValuesrc/hooks/useSlashCommands.tsnewInputValue并将光标移到末尾验证方式
/触发面板/clear)仍正常清空输入npm run test通过(typecheck + 单元测试)