Skip to content

Commit 178d25b

Browse files
committed
fix: address PR review feedback for auto-focus functionality
- Remove inconsistent setTimeout approach in ChatView.tsx - Fix race condition in ClineProvider.ts by combining sequential messages - Update message interfaces to support followUpAction property - Ensure all TypeScript types are properly defined
1 parent bf89d4e commit 178d25b

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,9 +1166,12 @@ export class ClineProvider
11661166
await this.initClineWithHistoryItem(historyItem) // Clears existing task.
11671167
}
11681168

1169-
await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
1170-
// Focus the input after loading the task
1171-
await this.postMessageToWebview({ type: "action", action: "focusInput" })
1169+
// Combine both actions into a single message to avoid race condition
1170+
await this.postMessageToWebview({
1171+
type: "action",
1172+
action: "chatButtonClicked",
1173+
followUpAction: "focusInput",
1174+
})
11721175
}
11731176

11741177
async exportTaskWithId(id: string) {

src/core/webview/webviewMessageHandler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,11 @@ export const webviewMessageHandler = async (
434434
}
435435
break
436436
case "showTaskWithId":
437-
provider.showTaskWithId(message.text!)
437+
await provider.showTaskWithId(message.text!)
438+
// Handle any follow-up action if specified
439+
if (message.followUpAction) {
440+
await provider.postMessageToWebview({ type: "action", action: message.followUpAction })
441+
}
438442
break
439443
case "condenseTaskContextRequest":
440444
provider.condenseTaskContext(message.text!)

src/shared/ExtensionMessage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export interface ExtensionMessage {
122122
| "didBecomeVisible"
123123
| "focusInput"
124124
| "switchTab"
125+
| string // Allow any string for flexibility
126+
followUpAction?: string // For follow-up actions after main message handling
125127
invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
126128
state?: ExtensionState
127129
images?: string[]

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export interface WebviewMessage {
244244
visibility?: ShareVisibility // For share visibility
245245
hasContent?: boolean // For checkRulesDirectoryResult
246246
checkOnly?: boolean // For deleteCustomMode check
247+
followUpAction?: string // For follow-up actions after main message handling
247248
codeIndexSettings?: {
248249
// Global state settings
249250
codebaseIndexEnabled: boolean

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
596596

597597
const startNewTask = useCallback(() => {
598598
vscode.postMessage({ type: "clearTask" })
599-
// Focus the textarea after starting a new task
600-
setTimeout(() => {
601-
textAreaRef.current?.focus()
602-
}, 100)
599+
// Focus the textarea directly after starting a new task
600+
textAreaRef.current?.focus()
603601
}, [])
604602

605603
// This logic depends on the useEffect[messages] above to set clineAsk,

0 commit comments

Comments
 (0)