fix(focus): stabilize focus across sidebar/tab and remove race in plus button path

This commit is contained in:
daniel-lxs 2025-10-30 16:24:20 -05:00
parent 9dfa496659
commit 96e499c965
No known key found for this signature in database
GPG key ID: 21C74479048B3AA6
2 changed files with 13 additions and 8 deletions

View file

@ -97,9 +97,6 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
await visibleProvider.removeClineFromStack()
await visibleProvider.refreshWorkspace()
await visibleProvider.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
// Send focusInput action immediately after chatButtonClicked
// This ensures the focus happens after the view has switched
await visibleProvider.postMessageToWebview({ type: "action", action: "focusInput" })
},
mcpButtonClicked: () => {
const visibleProvider = getVisibleProviderOrLog(outputChannel)
@ -197,9 +194,13 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
try {
await focusPanel(tabPanel, sidebarPanel)
// Send focus input message only for sidebar panels
if (sidebarPanel && getPanel() === sidebarPanel) {
provider.postMessageToWebview({ type: "action", action: "focusInput" })
// Send focus input message to webview after panel becomes focusable
// Use setTimeout to defer until after the panel reveal/focus completes
const activePanel = getPanel()
if (activePanel) {
setTimeout(() => {
provider.postMessageToWebview({ type: "action", action: "focusInput" })
}, 0)
}
} catch (error) {
outputChannel.appendLine(`Error focusing input: ${error}`)

View file

@ -787,11 +787,15 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
switch (message.action!) {
case "didBecomeVisible":
if (!isHidden && !sendingDisabled && !enableButtons) {
textAreaRef.current?.focus()
requestAnimationFrame(() => {
textAreaRef.current?.focus()
})
}
break
case "focusInput":
textAreaRef.current?.focus()
requestAnimationFrame(() => {
textAreaRef.current?.focus()
})
break
}
break