Skip to content

fix(desktop): scope file shortcuts to active sidebar tab - #2

Open
XDoldyuan wants to merge 1 commit into
xindong:mainfrom
XDoldyuan:fix/sidebar-file-shortcut-ownership
Open

fix(desktop): scope file shortcuts to active sidebar tab#2
XDoldyuan wants to merge 1 commit into
xindong:mainfrom
XDoldyuan:fix/sidebar-file-shortcut-ownership

Conversation

@XDoldyuan

@XDoldyuan XDoldyuan commented Aug 20, 2026

Copy link
Copy Markdown

这次改了什么

摘要

修复右侧侧边栏同时打开多个文件浏览页签时,Ctrl/Cmd+F 等文件快捷键始终被第一个已挂载页签处理的问题。现在仅当前激活且可见的文件页签拥有快捷键处理权。

变更类型

  • fix 缺陷修复

范围

  • 关联 Issue / 需求:用户反馈;暂无 Issue。
  • 本 PR 包含:限定文件浏览页签的快捷键与页内查找所有权;增加回归测试;让既有 Renderer 契约测试兼容 LF/CRLF。
  • 明确不包含:不调整文件浏览器视觉、布局、文案或快捷键组合;不改动其他侧边栏插件。
  • 用户可见变化:多个文件页签同时打开时,Ctrl/Cmd+FCtrl/Cmd+Shift+FCtrl/Cmd+S 只作用于当前激活且可见的文件页签。
  • 是否存在 breaking change:无。

UI 变化

  • 引用的设计规范:不涉及:本次仅修正现有快捷键事件的页签归属,不新增视觉、布局、文案或交互设计规则;原有快捷键组合与操作结果不变。

怎么验证的

自动验证

pnpm vitest run apps/desktop/src/renderer/__tests__/fileBodyShortcutOwnership.test.ts apps/desktop/src/renderer/__tests__/markdownTargetRendererContract.test.ts
结果:9 项通过。

pnpm --filter desktop run --if-present typecheck
结果:通过。

pnpm test:unit
结果:通过;根 runner 290 passed、0 failed,Desktop 及其余要求的 workspace 全部通过。

手工验证

不涉及:本次以快捷键所有权回归测试覆盖多页签挂载与 active/visible 状态切换。

未执行的验证

无。

风险

风险分类

  • 跨平台差异

影响与回滚

  • 影响范围:Desktop Renderer 右侧侧边栏文件浏览器的 Ctrl/Cmd+FCtrl/Cmd+Shift+FCtrl/Cmd+S 注册;另有一处既有源码契约断言改为同时接受 LF 与 CRLF。
  • 回滚 / 降级方式:回退提交 b5f3a3aaf8c4a827b29d02c0eff6211773cd487f

提交前检查

  • 已 review 完整 diff
  • 每个 commit 都带 DCO 签名(git commit -s,见 DCO
  • UI 改动已在「UI 变化」注明引用的设计规范章节(本次说明为不涉及设计规则)
  • 未提交凭证、令牌或授权文件
  • 已补充必要文档(本次无文档变更需求)
  • 已确认测试结果或说明未执行原因

Signed-off-by: yuanzhengjie <yuanzhengjie@xd.com>
@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown

Greptile Summary

此 PR 将文件快捷键和页面内查找所有权限制为当前激活且可见的文件浏览器标签,并兼容 Windows 的 CRLF 测试输入。

  • FileBodyView 增加可动态切换的快捷键开关。
  • 从右侧栏宿主状态传递激活与可见性条件。
  • 新增快捷键所有权回归测试,但目前只验证源码文本,未覆盖实际状态切换。
  • 放宽 Markdown renderer contract 测试的换行符匹配。

Confidence Score: 4/5

此 PR 看起来可以合并,但新增回归测试应改为覆盖实际标签状态切换,避免快捷键所有权再次失效时仍然通过。

运行时代码会随 active 和 shellVisible 正确启停监听器及查找所有权;剩余问题仅是新增测试使用源码字符串断言,不能真正验证该生命周期行为。

Files Needing Attention: apps/desktop/src/renderer/tests/fileBodyShortcutOwnership.test.ts

Important Files Changed

Filename Overview
apps/desktop/src/renderer/features/cc-agent/workdir-browse/FileBodyView.tsx 根据 shortcutsEnabled 正确注册或清理三个全局快捷键及 find-in-page ownership。
apps/desktop/src/renderer/features/right-sidebar/plugins/file-browser/FileBrowserBody.tsx 将宿主传入的 active 与 shellVisible 组合后传给 FileBodyView,当前宿主调用链已完整接线。
apps/desktop/src/renderer/tests/fileBodyShortcutOwnership.test.ts 新测试仅断言源码字符串,不能验证标签切换时的实际监听器和 ownership 生命周期。
apps/desktop/src/renderer/tests/markdownTargetRendererContract.test.ts 正则同时接受 LF 与 CRLF,修正 Windows 下的测试兼容性。
Prompt To Fix All With AI
### Issue 1
apps/desktop/src/renderer/__tests__/fileBodyShortcutOwnership.test.ts:30-33
**回归测试只检查源码文本**

该测试仅通过 `toContain` 和正则计数检查源码片段,没有挂载组件或模拟标签状态切换;后续即使属性转发、effect 依赖或监听器生命周期发生回归,只要这些文本仍存在,测试就会继续通过,无法保护本次修复的快捷键所有权行为。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix(desktop): scope file shortcuts to ac..." | Re-trigger Greptile

Comment on lines +30 to +33
it('enables file shortcuts only for the active visible tab', () => {
expect(fileBrowserBodySource).toContain('shortcutsEnabled={active && shellVisible}');
expect(fileBodySource).toContain('if (!shortcutsEnabled) return;');
expect(fileBodySource.match(/enabled: shortcutsEnabled/g)).toHaveLength(3);

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 回归测试只检查源码文本

该测试仅通过 toContain 和正则计数检查源码片段,没有挂载组件或模拟标签状态切换;后续即使属性转发、effect 依赖或监听器生命周期发生回归,只要这些文本仍存在,测试就会继续通过,无法保护本次修复的快捷键所有权行为。

Context Used: 使用和PR描述相同的语言进行评论 (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/__tests__/fileBodyShortcutOwnership.test.ts
Line: 30-33

Comment:
**回归测试只检查源码文本**

该测试仅通过 `toContain` 和正则计数检查源码片段,没有挂载组件或模拟标签状态切换;后续即使属性转发、effect 依赖或监听器生命周期发生回归,只要这些文本仍存在,测试就会继续通过,无法保护本次修复的快捷键所有权行为。

**Context Used:** 使用和PR描述相同的语言进行评论 ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@XDoldyuan

Copy link
Copy Markdown
Author

CodeQL is not triggering for this fork PR. As of August 28, 2026, the regular checks (client-ci/verify, pr-design-basis, and Greptile) are successful, but no CodeQL workflow run is attached to the PR head commit. GitHub therefore reports “Code scanning is waiting for results from CodeQL” and keeps the merge blocked. Could a maintainer please re-trigger/approve CodeQL for this PR and, if needed, update the branch-protection/code-scanning requirement for external fork PRs? This appears to be a repository workflow/branch-protection issue rather than a code failure.

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