Skip to content

Commit 96e499c

Browse files
committed
fix(focus): stabilize focus across sidebar/tab and remove race in plus button path
1 parent 9dfa496 commit 96e499c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/activate/registerCommands.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
9797
await visibleProvider.removeClineFromStack()
9898
await visibleProvider.refreshWorkspace()
9999
await visibleProvider.postMessageToWebview({ type: "action", action: "chatButtonClicked" })
100-
// Send focusInput action immediately after chatButtonClicked
101-
// This ensures the focus happens after the view has switched
102-
await visibleProvider.postMessageToWebview({ type: "action", action: "focusInput" })
103100
},
104101
mcpButtonClicked: () => {
105102
const visibleProvider = getVisibleProviderOrLog(outputChannel)
@@ -197,9 +194,13 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
197194
try {
198195
await focusPanel(tabPanel, sidebarPanel)
199196

200-
// Send focus input message only for sidebar panels
201-
if (sidebarPanel && getPanel() === sidebarPanel) {
202-
provider.postMessageToWebview({ type: "action", action: "focusInput" })
197+
// Send focus input message to webview after panel becomes focusable
198+
// Use setTimeout to defer until after the panel reveal/focus completes
199+
const activePanel = getPanel()
200+
if (activePanel) {
201+
setTimeout(() => {
202+
provider.postMessageToWebview({ type: "action", action: "focusInput" })
203+
}, 0)
203204
}
204205
} catch (error) {
205206
outputChannel.appendLine(`Error focusing input: ${error}`)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,11 +787,15 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
787787
switch (message.action!) {
788788
case "didBecomeVisible":
789789
if (!isHidden && !sendingDisabled && !enableButtons) {
790-
textAreaRef.current?.focus()
790+
requestAnimationFrame(() => {
791+
textAreaRef.current?.focus()
792+
})
791793
}
792794
break
793795
case "focusInput":
794-
textAreaRef.current?.focus()
796+
requestAnimationFrame(() => {
797+
textAreaRef.current?.focus()
798+
})
795799
break
796800
}
797801
break

0 commit comments

Comments
 (0)