Keep composer focused after toolbar and mode changes
- Add a shared composer-focus scheduler in `ChatView` - Refocus composer after runtime mode, model, effort, and env mode selections - Let `BranchToolbar` request composer focus after branch/worktree actions
This commit is contained in:
1 parent
8dd107429e
commit
dd23bd73d9
2 files changed
+36
-3
No files matched your search
@@ -25,9 +25,15 @@ interface BranchToolbarProps {
|
||||
envMode: "local" | "worktree";
|
||||
onEnvModeChange: (mode: "local" | "worktree") => void;
|
||||
envLocked: boolean;
|
||||
onComposerFocusRequest?: () => void;
|
||||
}
|
||||
|
||||
export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: BranchToolbarProps) {
|
||||
export default function BranchToolbar({
|
||||
envMode,
|
||||
onEnvModeChange,
|
||||
envLocked,
|
||||
onComposerFocusRequest,
|
||||
}: BranchToolbarProps) {
|
||||
const { state, dispatch } = useStore();
|
||||
const api = useNativeApi();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -123,6 +129,7 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
|
||||
setThreadError(null);
|
||||
setThreadBranch(branch.name, null);
|
||||
setIsBranchMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -135,6 +142,7 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
|
||||
// Secondary worktree → point the thread at that worktree path.
|
||||
setThreadBranch(branch.name, isMainWorktree ? null : branch.worktreePath);
|
||||
setIsBranchMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -143,6 +151,7 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
|
||||
setThreadError(null);
|
||||
setThreadBranch(branch.name, activeWorktreePath);
|
||||
setIsBranchMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -156,6 +165,7 @@ export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: B
|
||||
setThreadBranch(name, activeWorktreePath);
|
||||
setBranchQuery("");
|
||||
setIsBranchMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -298,6 +298,11 @@ export default function ChatView() {
|
||||
const cursor = textarea.value.length;
|
||||
textarea.setSelectionRange(cursor, cursor);
|
||||
}, []);
|
||||
const scheduleComposerFocus = useCallback(() => {
|
||||
window.requestAnimationFrame(() => {
|
||||
focusComposer();
|
||||
});
|
||||
}, [focusComposer]);
|
||||
const toggleTerminalVisibility = useCallback(() => {
|
||||
if (!activeThreadId) return;
|
||||
dispatch({
|
||||
@@ -369,6 +374,7 @@ export default function ChatView() {
|
||||
const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => {
|
||||
if (mode === state.runtimeMode) return;
|
||||
dispatch({ type: "SET_RUNTIME_MODE", mode });
|
||||
scheduleComposerFocus();
|
||||
if (!api) return;
|
||||
|
||||
const sessionIds = state.threads
|
||||
@@ -898,7 +904,19 @@ export default function ChatView() {
|
||||
threadId: activeThread.id,
|
||||
model: resolveModelSlug(model),
|
||||
});
|
||||
scheduleComposerFocus();
|
||||
};
|
||||
const onEffortSelect = (effort: ReasoningEffort) => {
|
||||
setSelectedEffort(effort);
|
||||
scheduleComposerFocus();
|
||||
};
|
||||
const onEnvModeChange = useCallback(
|
||||
(mode: "local" | "worktree") => {
|
||||
setEnvMode(mode);
|
||||
scheduleComposerFocus();
|
||||
},
|
||||
[scheduleComposerFocus],
|
||||
);
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
@@ -1302,7 +1320,7 @@ export default function ChatView() {
|
||||
<Separator orientation="vertical" className="mx-0.5 h-4" />
|
||||
|
||||
{/* Reasoning effort */}
|
||||
<ReasoningEffortPicker effort={selectedEffort} onEffortChange={setSelectedEffort} />
|
||||
<ReasoningEffortPicker effort={selectedEffort} onEffortChange={onEffortSelect} />
|
||||
|
||||
{/* Divider */}
|
||||
<Separator orientation="vertical" className="mx-0.5 h-4" />
|
||||
@@ -1405,7 +1423,12 @@ export default function ChatView() {
|
||||
</div>
|
||||
|
||||
{isGitRepo && (
|
||||
<BranchToolbar envMode={envMode} onEnvModeChange={setEnvMode} envLocked={envLocked} />
|
||||
<BranchToolbar
|
||||
envMode={envMode}
|
||||
onEnvModeChange={onEnvModeChange}
|
||||
envLocked={envLocked}
|
||||
onComposerFocusRequest={scheduleComposerFocus}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeThread.terminalOpen && api && activeProject && (
|
||||
|
||||
Reference in new issue
Block a user