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
This commit is contained in:
Roo Code 2025-07-28 22:43:51 +00:00
parent bf89d4e99f
commit 178d25b3b9
5 changed files with 16 additions and 8 deletions

View file

@ -1166,9 +1166,12 @@ export class ClineProvider
await this.initClineWithHistoryItem(historyItem) // Clears existing task.
}
await this.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
// Focus the input after loading the task
await this.postMessageToWebview({ type: "action", action: "focusInput" })
// Combine both actions into a single message to avoid race condition
await this.postMessageToWebview({
type: "action",
action: "chatButtonClicked",
followUpAction: "focusInput",
})
}
async exportTaskWithId(id: string) {

View file

@ -434,7 +434,11 @@ export const webviewMessageHandler = async (
}
break
case "showTaskWithId":
provider.showTaskWithId(message.text!)
await provider.showTaskWithId(message.text!)
// Handle any follow-up action if specified
if (message.followUpAction) {
await provider.postMessageToWebview({ type: "action", action: message.followUpAction })
}
break
case "condenseTaskContextRequest":
provider.condenseTaskContext(message.text!)

View file

@ -122,6 +122,8 @@ export interface ExtensionMessage {
| "didBecomeVisible"
| "focusInput"
| "switchTab"
| string // Allow any string for flexibility
followUpAction?: string // For follow-up actions after main message handling
invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
state?: ExtensionState
images?: string[]

View file

@ -244,6 +244,7 @@ export interface WebviewMessage {
visibility?: ShareVisibility // For share visibility
hasContent?: boolean // For checkRulesDirectoryResult
checkOnly?: boolean // For deleteCustomMode check
followUpAction?: string // For follow-up actions after main message handling
codeIndexSettings?: {
// Global state settings
codebaseIndexEnabled: boolean

View file

@ -596,10 +596,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
const startNewTask = useCallback(() => {
vscode.postMessage({ type: "clearTask" })
// Focus the textarea after starting a new task
setTimeout(() => {
textAreaRef.current?.focus()
}, 100)
// Focus the textarea directly after starting a new task
textAreaRef.current?.focus()
}, [])
// This logic depends on the useEffect[messages] above to set clineAsk,