浏览代码

fix: change keybinding to Shift+Alt+C, fix explorer commands fallback on keyboard invocation

Developer 1 月之前
父节点
当前提交
7325a3b05d
共有 4 个文件被更改,包括 76 次插入6 次删除
  1. 0 0
      dist/extension.js
  2. 58 0
      docs/superpowers/plans/2026-07-14-keybindings-plan.md
  3. 4 4
      package.json
  4. 14 2
      src/extension.ts

文件差异内容过多而无法显示
+ 0 - 0
dist/extension.js


+ 58 - 0
docs/superpowers/plans/2026-07-14-keybindings-plan.md

@@ -0,0 +1,58 @@
+# Copy AI Ctx 快捷键支持 — 实现计划
+
+> **面向 AI 代理的工作者:** 必需子技能:使用 superpowers:subagent-driven-development(推荐)或 superpowers:executing-plans 逐任务实现此计划。步骤使用复选框(`- [ ]`)语法来跟踪进度。
+
+**目标:** 为 Copy AI Ctx 扩展的 4 个命令添加 `Ctrl+K C`(macOS: `Cmd+K C`)快捷键支持。
+
+**架构:** 仅在 `package.json` 的 `contributes` 下新增 `keybindings` 数组,通过 VS Code `when` 条件自动匹配上下文(编辑器选中/未选中、资源管理器单选/多选),无需修改 TypeScript 代码。
+
+**技术栈:** VS Code extension manifest(`package.json`)
+
+---
+
+### 任务 1:在 package.json 中添加 keybindings 配置
+
+**文件:**
+- 修改:`package.json`
+
+- [ ] **步骤 1:在 contributes 中新增 keybindings 数组**
+
+在 `package.json` 的 `contributes` 对象中,在 `menus` 同级新增 `keybindings` 数组:
+
+```jsonc
+"keybindings": [
+  {
+    "key": "ctrl+k ctrl+c",
+    "command": "copy-ai-ctx.copySelection",
+    "when": "editorHasSelection"
+  },
+  {
+    "key": "ctrl+k ctrl+c",
+    "command": "copy-ai-ctx.copyFile",
+    "when": "!editorHasSelection && editorFocus"
+  },
+  {
+    "key": "ctrl+k ctrl+c",
+    "command": "copy-ai-ctx.copySelectedFiles",
+    "when": "explorerViewletVisible && !listMultiSelection"
+  },
+  {
+    "key": "ctrl+k ctrl+c",
+    "command": "copy-ai-ctx.copyMultiFiles",
+    "when": "explorerViewletVisible && listMultiSelection"
+  }
+]
+```
+
+- [ ] **步骤 2:运行 build 验证配置无语法错误**
+
+运行:`npm run build`
+
+预期:esbuild 打包成功,无报错退出。
+
+- [ ] **步骤 3:Commit**
+
+```bash
+git add package.json
+git commit -m "feat: add Ctrl+K C keybinding for all 4 commands"
+```

+ 4 - 4
package.json

@@ -70,22 +70,22 @@
     },
     "keybindings": [
       {
-        "key": "ctrl+k ctrl+c",
+        "key": "shift+alt+c",
         "command": "copy-ai-ctx.copySelection",
         "when": "editorHasSelection"
       },
       {
-        "key": "ctrl+k ctrl+c",
+        "key": "shift+alt+c",
         "command": "copy-ai-ctx.copyFile",
         "when": "!editorHasSelection && editorFocus"
       },
       {
-        "key": "ctrl+k ctrl+c",
+        "key": "shift+alt+c",
         "command": "copy-ai-ctx.copySelectedFiles",
         "when": "explorerViewletVisible && !listMultiSelection"
       },
       {
-        "key": "ctrl+k ctrl+c",
+        "key": "shift+alt+c",
         "command": "copy-ai-ctx.copyMultiFiles",
         "when": "explorerViewletVisible && listMultiSelection"
       }

+ 14 - 2
src/extension.ts

@@ -24,14 +24,26 @@ export function activate(context: vscode.ExtensionContext) {
 
   context.subscriptions.push(
     vscode.commands.registerCommand('copy-ai-ctx.copySelectedFiles', (args) => {
-      if (!args) return;
+      if (!args) {
+        // keyboard shortcut invocation: fallback to active editor file
+        const editor = vscode.window.activeTextEditor;
+        if (!editor) return;
+        copySingleItem(editor.document.uri);
+        return;
+      }
       copySingleItem(args as vscode.Uri);
     }),
   );
 
   context.subscriptions.push(
     vscode.commands.registerCommand('copy-ai-ctx.copyMultiFiles', (...args) => {
-      if (args.length < 2) return;
+      if (args.length < 2) {
+        // keyboard shortcut invocation: fallback to active editor file
+        const editor = vscode.window.activeTextEditor;
+        if (!editor) return;
+        copyMultiFiles([editor.document.uri]);
+        return;
+      }
       // args[0] = clicked resource URI
       // args[1] might be array (standard) or individual URI (variadic)
       const resources = Array.isArray(args[1]) ? args[1] : args.slice(1);

部分文件因为文件数量过多而无法显示