diff --git a/packages/vscode/src/ChatViewProvider.ts b/packages/vscode/src/ChatViewProvider.ts index d289b31e..e6e7852c 100644 --- a/packages/vscode/src/ChatViewProvider.ts +++ b/packages/vscode/src/ChatViewProvider.ts @@ -200,6 +200,18 @@ export class ChatViewProvider implements vscode.WebviewViewProvider { } } + public focusChatInput(): void { + if (!this._view) { + return; + } + + this._view.show(true); + void this._view.webview.postMessage({ + type: 'command', + command: 'focusChatInput', + }); + } + public addContextSelection(selection: { filePath: string; filename: string; text: string }) { if (!this._view) { return; diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index b7a39255..f886e363 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -182,7 +182,10 @@ export async function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand('openchamber.focusChat', async () => { - await vscode.commands.executeCommand('openchamber.chatView.focus'); + if (!(await revealChatViewForPayload())) { + return; + } + chatViewProvider?.focusChatInput(); }) ); diff --git a/packages/vscode/webview/main.tsx b/packages/vscode/webview/main.tsx index fb9837ad..3a83a155 100644 --- a/packages/vscode/webview/main.tsx +++ b/packages/vscode/webview/main.tsx @@ -16,6 +16,7 @@ import type { VSCodeActiveEditorFile } from '@/sync/input-store'; import { usePermissionStore } from '@openchamber/ui/stores/permissionStore'; import { processVSCodePermissionAutoAccept } from '@openchamber/ui/sync/vscode-permission-auto-accept'; import type { PermissionRequest } from '@opencode-ai/sdk/v2/client'; +import { focusChatInput } from '@openchamber/ui/components/chat/composer/editor/dom'; type ConnectionStatus = 'connecting' | 'connected' | 'error' | 'disconnected'; type PanelType = 'chat' | 'agentManager'; @@ -1292,6 +1293,10 @@ window.fetch = async (input: RequestInfo | URL, init?: RequestInit) => { return originalFetch(input as RequestInfo, init); }; +onCommand('focusChatInput', () => { + focusChatInput(); +}); + onCommand('addContextSelection', (payload) => { const { filePath, filename, text } = payload as { filePath?: unknown; filename?: unknown; text?: unknown }; if (typeof filePath !== 'string' || typeof filename !== 'string' || typeof text !== 'string') { @@ -1306,7 +1311,9 @@ onCommand('addContextSelection', (payload) => { import('@/sync/input-store').then(({ useInputStore }) => { const file = new File([new Blob([text], { type: 'text/plain' })], trimmedFilename, { type: 'text/plain' }); - void useInputStore.getState().addVSCodeSelectionAttachment(trimmedPath, file); + void useInputStore.getState().addVSCodeSelectionAttachment(trimmedPath, file).finally(() => { + focusChatInput(); + }); }); });