diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 905e657b37..9e3a76f5aa 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1167,6 +1167,8 @@ export class ClineProvider } await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" }) + // Focus the input after loading the task + await this.postMessageToWebview({ type: "action", action: "focusInput" }) } async exportTaskWithId(id: string) { diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index c739c2ade8..e8ba3c112e 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -288,6 +288,8 @@ export const webviewMessageHandler = async ( // agentically running promises in old instance don't affect our new // task. This essentially creates a fresh slate for the new task. await provider.initClineWithTask(message.text, message.images) + // Focus the input after creating a new task + await provider.postMessageToWebview({ type: "action", action: "focusInput" }) break case "customInstructions": await provider.updateCustomInstructions(message.text) diff --git a/test-focus-implementation.md b/test-focus-implementation.md new file mode 100644 index 0000000000..544536c58a --- /dev/null +++ b/test-focus-implementation.md @@ -0,0 +1,29 @@ +# Test Plan for Auto-Focus Chat Input Feature + +## Changes Made: + +1. **ChatView.tsx** - Modified `startNewTask` function to focus textarea after clearing task +2. **ClineProvider.ts** - Added focus action after showing task with ID +3. **webviewMessageHandler.ts** - Added focus action after creating new task + +## Test Scenarios: + +### 1. New Task Creation + +- Click "Start New Task" button +- Expected: Chat input should automatically receive focus + +### 2. Opening Past Task from History + +- Click on a task from history +- Expected: Chat input should automatically receive focus after task loads + +### 3. Focus Action Handler + +- The existing `focusInput` action handler in ChatView.tsx (line 720) will handle the focus request + +## Implementation Details: + +- Used `setTimeout` with 100ms delay in `startNewTask` to ensure DOM is ready +- Used `postMessageToWebview` with `focusInput` action for consistent focus handling +- Leveraged existing focus infrastructure in the codebase diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index efd2db856c..cc24faeb4f 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -594,7 +594,13 @@ const ChatViewComponent: React.ForwardRefRenderFunction vscode.postMessage({ type: "clearTask" }), []) + const startNewTask = useCallback(() => { + vscode.postMessage({ type: "clearTask" }) + // Focus the textarea after starting a new task + setTimeout(() => { + textAreaRef.current?.focus() + }, 100) + }, []) // This logic depends on the useEffect[messages] above to set clineAsk, // after which buttons are shown and we then send an askResponse to the