fix (vscode): focus chat input after opening the chat view
Opens the chat view before focusing the input Routes a new webview command to focus the composer Refocuses the input after adding a VS Code selection attachment
This commit is contained in:
@@ -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 }) {
|
public addContextSelection(selection: { filePath: string; filename: string; text: string }) {
|
||||||
if (!this._view) {
|
if (!this._view) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -182,7 +182,10 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||||||
|
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
vscode.commands.registerCommand('openchamber.focusChat', async () => {
|
vscode.commands.registerCommand('openchamber.focusChat', async () => {
|
||||||
await vscode.commands.executeCommand('openchamber.chatView.focus');
|
if (!(await revealChatViewForPayload())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chatViewProvider?.focusChatInput();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import type { VSCodeActiveEditorFile } from '@/sync/input-store';
|
|||||||
import { usePermissionStore } from '@openchamber/ui/stores/permissionStore';
|
import { usePermissionStore } from '@openchamber/ui/stores/permissionStore';
|
||||||
import { processVSCodePermissionAutoAccept } from '@openchamber/ui/sync/vscode-permission-auto-accept';
|
import { processVSCodePermissionAutoAccept } from '@openchamber/ui/sync/vscode-permission-auto-accept';
|
||||||
import type { PermissionRequest } from '@opencode-ai/sdk/v2/client';
|
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 ConnectionStatus = 'connecting' | 'connected' | 'error' | 'disconnected';
|
||||||
type PanelType = 'chat' | 'agentManager';
|
type PanelType = 'chat' | 'agentManager';
|
||||||
@@ -1292,6 +1293,10 @@ window.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
|||||||
return originalFetch(input as RequestInfo, init);
|
return originalFetch(input as RequestInfo, init);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onCommand('focusChatInput', () => {
|
||||||
|
focusChatInput();
|
||||||
|
});
|
||||||
|
|
||||||
onCommand('addContextSelection', (payload) => {
|
onCommand('addContextSelection', (payload) => {
|
||||||
const { filePath, filename, text } = payload as { filePath?: unknown; filename?: unknown; text?: unknown };
|
const { filePath, filename, text } = payload as { filePath?: unknown; filename?: unknown; text?: unknown };
|
||||||
if (typeof filePath !== 'string' || typeof filename !== 'string' || typeof text !== 'string') {
|
if (typeof filePath !== 'string' || typeof filename !== 'string' || typeof text !== 'string') {
|
||||||
@@ -1306,7 +1311,9 @@ onCommand('addContextSelection', (payload) => {
|
|||||||
|
|
||||||
import('@/sync/input-store').then(({ useInputStore }) => {
|
import('@/sync/input-store').then(({ useInputStore }) => {
|
||||||
const file = new File([new Blob([text], { type: 'text/plain' })], trimmedFilename, { type: 'text/plain' });
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user