Keep chat composer focused after toolbar and mode interactions #49
main fromcodething/d7b34bf2·merged by juliusmarminge View on GitHubSummary#
- keep the composer focused after branch selection and branch creation actions in
BranchToolbar - add a scheduled composer focus helper in
ChatViewusingrequestAnimationFrameto restore focus after UI updates - trigger composer refocus after runtime mode changes, model selection, reasoning effort changes, and environment mode toggles
- wire
BranchToolbarto request composer focus via a new optional callback prop
Testing#
- Not run (tests not included in provided changes)
- Manually verify changing runtime mode keeps the composer focused
- Manually verify model and reasoning effort selection return focus to the composer
- Manually verify switching env mode and selecting/creating branches returns focus to the composer
Summary by CodeRabbit#
- New Features
- Composer now automatically focuses after branch/worktree actions (select, checkout, create) for a smoother workflow.
- Composer auto-focuses after model changes, reasoning-effort adjustments, and environment or runtime mode switches to reduce manual clicks.
- Focus behavior is coordinated across UI controls so changes that affect context consistently return focus to the composer.
- 1
Keep the ChatView composer focused after BranchToolbar interactions, env mode toggles, model changes, and reasoning effort selections in ChatView.tsx and BranchToolbar.tsx#
Add
onComposerFocusRequesttoBranchToolbarand invoke it after branch select/create; wire focus scheduling inChatViewviarequestAnimationFrameafter env mode, model, and reasoning effort changes.📍Where to Start#
Start with the
scheduleComposerFocushelper and its call sites in ChatView.tsx, then review howonComposerFocusRequestis threaded and invoked in BranchToolbar.tsx.
Macroscope summarized c9fae23.Greptile Summary
This PR ensures the chat composer textarea retains focus after various toolbar and mode interactions (model selection, reasoning effort, runtime mode toggle, env mode switch, and branch selection/creation). It introduces a
scheduleComposerFocushelper inChatViewthat usesrequestAnimationFrameto restore focus after UI updates, and passes it as a callback prop (onComposerFocusRequest) toBranchToolbar.- Added
scheduleComposerFocusinChatViewwrapping the existingfocusComposerinrequestAnimationFrame - Wired focus restoration into
onModelSelect,onEffortSelect,handleRuntimeModeChange, and a newonEnvModeChangecallback BranchToolbaraccepts an optionalonComposerFocusRequestprop, called after branch selection, branch creation, and env mode toggle actions- No functional issues found; the separation between
onEnvModeChange(env mode toggle) andonComposerFocusRequest(branch actions) is clean with no double-focus risk
Confidence Score: 4/5
- This PR is safe to merge — it only adds focus management callbacks with no changes to business logic or data flow.
- The changes are narrowly scoped to UX focus management. The
requestAnimationFrame-based approach is appropriate for deferring focus after React state updates. No business logic, data flow, or API interactions are modified. Minor style inconsistency (mixeduseCallbackusage) is not a functional concern. - No files require special attention.
Important Files Changed
Filename Overview apps/web/src/components/ChatView.tsx Adds scheduleComposerFocushelper usingrequestAnimationFrame, and wires it into model selection, reasoning effort, runtime mode, and env mode changes. Clean separation of concerns withonEffortSelect,onEnvModeChange, and theonComposerFocusRequestprop.apps/web/src/components/BranchToolbar.tsx Adds optional onComposerFocusRequestcallback prop, invoked after branch selection and branch creation actions close the branch menu. Straightforward and correct integration.Sequence Diagram
Last reviewed commit: c604768sequenceDiagram participant User participant ChatView participant BranchToolbar participant Composer as Textarea (Composer) Note over User,Composer: Model / Effort / Runtime Mode Change User->>ChatView: Clicks model/effort/runtime toggle ChatView->>ChatView: Update state (dispatch/setState) ChatView->>ChatView: scheduleComposerFocus() ChatView->>Composer: requestAnimationFrame → focus() Note over User,Composer: Env Mode Toggle User->>BranchToolbar: Clicks env mode button BranchToolbar->>ChatView: onEnvModeChange(mode) ChatView->>ChatView: setEnvMode + scheduleComposerFocus() ChatView->>Composer: requestAnimationFrame → focus() Note over User,Composer: Branch Selection / Creation User->>BranchToolbar: Selects or creates branch BranchToolbar->>BranchToolbar: Close menu, update thread BranchToolbar->>ChatView: onComposerFocusRequest() ChatView->>ChatView: scheduleComposerFocus() ChatView->>Composer: requestAnimationFrame → focus()- Added
- 2 files reviewed, 1 comment [Edit Code Review Agent Settings](https://app.greptile.com/review/github) | [Greptile](https://greptile.com?utm_source=greptile_expert&utm_medium=github&utm_campaign=code_reviews)@@ -813,4 +819,9 @@813819 threadId: activeThread.id,814820 model: resolveModelSlug(model),815821 });822+ scheduleComposerFocus();823+ };824+ const onEffortSelect = (effort: ReasoningEffort) => {825+ setSelectedEffort(effort);826+ scheduleComposerFocus();816827 };
Inconsistent memoization with
onEnvModeChange
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!onEnvModeChange(line 828) is wrapped inuseCallback, butonEffortSelectandonModelSelectare plain arrow functions. Since all three follow the same pattern (set state +scheduleComposerFocus), it would be more consistent to either wrap all of them inuseCallbackor none of them. This isn't a bug sinceReasoningEffortPickerisn't memoized, but worth keeping consistent. juliusmarminge merged thisb7fb0b8
juliusmarminge closed this
🧹 Nitpick comments (1)
apps/web/src/components/ChatView.tsx (1)
815-826: StabilizeonModelSelectby depending onactiveThreadIdinstead ofactiveThread. Using the whole thread object will churn the callback whenever the thread updates; the id keeps memoization effective.♻️ Suggested tweak
- const onModelSelect = useCallback( - (model: ModelSlug) => { - if (!activeThread) return; - dispatch({ - type: "SET_THREAD_MODEL", - threadId: activeThread.id, - model: resolveModelSlug(model), - }); - scheduleComposerFocus(); - }, - [activeThread, dispatch, scheduleComposerFocus], - ); + const onModelSelect = useCallback( + (model: ModelSlug) => { + if (!activeThreadId) return; + dispatch({ + type: "SET_THREAD_MODEL", + threadId: activeThreadId, + model: resolveModelSlug(model), + }); + scheduleComposerFocus(); + }, + [activeThreadId, dispatch, scheduleComposerFocus], + );
Sign in to join this conversation.
Walkthrough#
Added an optional
onComposerFocusRequestprop to BranchToolbar and threaded it through ChatView. ChatView introducesscheduleComposerFocus(deferred via requestAnimationFrame) and calls it after branch/worktree interactions, model/effort/env/runtime changes to refocus the composer.Changes#
apps/web/src/components/BranchToolbar.tsxonComposerFocusRequest?: () => voidtoBranchToolbarPropsand invoke it after branch selection, worktree path changes, checkout mutations, and branch creation to request composer focus.apps/web/src/components/ChatView.tsxscheduleComposerFocus(requestAnimationFrame). Wrapped handlers—model select, reasoning effort select, env mode change, and runtime mode change—to callscheduleComposerFocus. Replaced directsetEnvModeusage withonEnvModeChangepassed toBranchToolbarand wiredonComposerFocusRequest={scheduleComposerFocus}.Sequence Diagram(s)#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~40 minutes
🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)#
⚔️
apps/server/src/wsServer.test.ts(content)⚔️
apps/server/src/wsServer.ts(content)⚔️
apps/web/src/components/BranchToolbar.tsx(content)⚔️
apps/web/src/components/ChatView.tsx(content)⚔️
apps/web/src/components/Sidebar.tsx(content)⚔️
apps/web/src/components/ThreadTerminalDrawer.tsx(content)⚔️
apps/web/src/lib/utils.ts(content)⚔️
apps/web/src/terminal-links.ts(content)⚔️
apps/web/src/wsNativeApi.ts(content)⚔️
packages/contracts/src/index.ts(content)⚔️
packages/contracts/src/ipc.ts(content)These conflicts must be resolved before merging into
main.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.