fix: chat input submit via acceptInput + query param, clipboard paste fallback

This commit is contained in:
2026-03-07 15:24:32 +09:00
parent 0bd525a54c
commit b42475c610

View File

@@ -263,18 +263,18 @@ async function handleCommand(filePath: string) {
return; return;
} }
// General text: try to open chat panel and paste // General text: send to chat panel with query + submit
const chatCommands = [ let chatOpened = false;
'workbench.action.chat.open',
'workbench.panel.chat.view.copilot.focus', // Method 1: Try opening chat with query parameter (fills + auto-focuses)
'workbench.action.chat.openEditSession', const chatOpenCommands = [
'workbench.action.openChat', { cmd: 'workbench.action.chat.open', args: { query: command.text } },
{ cmd: 'workbench.panel.chat.view.copilot.focus', args: undefined },
]; ];
let chatOpened = false; for (const { cmd, args } of chatOpenCommands) {
for (const cmd of chatCommands) {
try { try {
await vscode.commands.executeCommand(cmd); await vscode.commands.executeCommand(cmd, args);
chatOpened = true; chatOpened = true;
console.log(`Gravity Bridge: chat opened with "${cmd}"`); console.log(`Gravity Bridge: chat opened with "${cmd}"`);
break; break;
@@ -282,11 +282,31 @@ async function handleCommand(filePath: string) {
} }
if (chatOpened) { if (chatOpened) {
await new Promise(resolve => setTimeout(resolve, 500)); 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(); const oldClipboard = await vscode.env.clipboard.readText();
await vscode.env.clipboard.writeText(command.text); await vscode.env.clipboard.writeText(command.text);
await vscode.commands.executeCommand('editor.action.clipboardPasteAction'); await vscode.commands.executeCommand('editor.action.clipboardPasteAction');
await vscode.env.clipboard.writeText(oldClipboard); await vscode.env.clipboard.writeText(oldClipboard);
console.log('Gravity Bridge: fallback to clipboard paste (no submit)');
}
} }
// Always mark as consumed + show notification // Always mark as consumed + show notification