From b42475c610a9a5520a9c9653e69dc6e7486b8dff Mon Sep 17 00:00:00 2001 From: CD Date: Sat, 7 Mar 2026 15:24:32 +0900 Subject: [PATCH] fix: chat input submit via acceptInput + query param, clipboard paste fallback --- extension/src/extension.ts | 48 +++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 6e15255..9a9a3f3 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -263,18 +263,18 @@ async function handleCommand(filePath: string) { return; } - // General text: try to open chat panel and paste - const chatCommands = [ - 'workbench.action.chat.open', - 'workbench.panel.chat.view.copilot.focus', - 'workbench.action.chat.openEditSession', - 'workbench.action.openChat', + // General text: send to chat panel with query + submit + let chatOpened = false; + + // Method 1: Try opening chat with query parameter (fills + auto-focuses) + const chatOpenCommands = [ + { cmd: 'workbench.action.chat.open', args: { query: command.text } }, + { cmd: 'workbench.panel.chat.view.copilot.focus', args: undefined }, ]; - let chatOpened = false; - for (const cmd of chatCommands) { + for (const { cmd, args } of chatOpenCommands) { try { - await vscode.commands.executeCommand(cmd); + await vscode.commands.executeCommand(cmd, args); chatOpened = true; console.log(`Gravity Bridge: chat opened with "${cmd}"`); break; @@ -282,11 +282,31 @@ async function handleCommand(filePath: string) { } if (chatOpened) { - await new Promise(resolve => setTimeout(resolve, 500)); - const oldClipboard = await vscode.env.clipboard.readText(); - await vscode.env.clipboard.writeText(command.text); - await vscode.commands.executeCommand('editor.action.clipboardPasteAction'); - await vscode.env.clipboard.writeText(oldClipboard); + await new Promise(resolve => setTimeout(resolve, 300)); + + // Try to submit the chat input + const submitCommands = [ + 'workbench.action.chat.acceptInput', + 'workbench.action.chat.submit', + ]; + let submitted = false; + for (const cmd of submitCommands) { + try { + await vscode.commands.executeCommand(cmd); + submitted = true; + console.log(`Gravity Bridge: chat submitted with "${cmd}"`); + break; + } catch { /* try next */ } + } + + if (!submitted) { + // Fallback: paste into focused input if query param didn't work + const oldClipboard = await vscode.env.clipboard.readText(); + await vscode.env.clipboard.writeText(command.text); + await vscode.commands.executeCommand('editor.action.clipboardPasteAction'); + await vscode.env.clipboard.writeText(oldClipboard); + console.log('Gravity Bridge: fallback to clipboard paste (no submit)'); + } } // Always mark as consumed + show notification