fix: simulate Enter key after clipboard paste for chat submission

This commit is contained in:
2026-03-07 15:29:12 +09:00
parent b42475c610
commit 35f39abf39

View File

@@ -300,12 +300,31 @@ async function handleCommand(filePath: string) {
} }
if (!submitted) { if (!submitted) {
// Fallback: paste into focused input if query param didn't work // Fallback: paste into focused input then simulate Enter
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)');
// Wait for paste to complete, then simulate Enter
await new Promise(resolve => setTimeout(resolve, 200));
// Try multiple ways to submit/press Enter
const enterMethods = [
'workbench.action.chat.acceptInput',
'default:type', // with \n
];
for (const method of enterMethods) {
try {
if (method === 'default:type') {
await vscode.commands.executeCommand(method, { text: '\n' });
} else {
await vscode.commands.executeCommand(method);
}
console.log(`Gravity Bridge: Enter sent via "${method}"`);
break;
} catch { /* try next */ }
}
} }
} }