refactor: 使用 native getSelectedContent 替代剪贴板轮询取词#525
Conversation
- 移除超时常量 CLIPBOARD_COPY_WAIT_TIMEOUT_MS、KEY_RELEASE_WAIT_TIMEOUT_MS、GLOBAL_SHORTCUT_COOLDOWN_MS - 简化 captureSelectedTextContext 方法,直接调用 native getSelectedContent() - 移除防抖逻辑,native 层自动处理按键释放和剪贴板暂停 - 支持获取文本、图片、文件三种类型的选中内容 - 移除对 clipboardManager 的依赖 - 新增 WindowManager.getSelectedContent 类型定义
There was a problem hiding this comment.
Code Review
This pull request replaces the manual clipboard-delay and key-release waiting logic in settings.ts with a new native method, NativeWindowManager.getSelectedContent(), which retrieves selected text, images, or files directly. Feedback on these changes suggests adding a defensive check to ensure the returned content is a valid array, dynamically determining if captured file paths are directories or files using fs.statSync (and importing fs), and using a discriminated union type for getSelectedContent to improve type safety.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
- 使用 discriminated union 类型提供更强的类型安全性和自动类型收窄 - 添加防御性检查,确保 contents 是有效数组后再访问属性 - 使用 fs.statSync 动态判断文件/目录类型,避免硬编码 - 导入 fs 模块以支持文件状态检查 - 添加错误处理,文件读取失败时使用默认值
关联 native 相关功能 #9