Skip to content

Commit ad0e7d0

Browse files
committed
fix(web): open branch picker directly from its shortcut
1 parent e2e19c3 commit ad0e7d0

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

‎apps/web/src/components/BranchToolbar.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ import {
3535
resolvePreviousWorktreeSeed,
3636
shouldShowEnvironmentIndicator,
3737
} from "./BranchToolbar.logic";
38-
import { BranchToolbarBranchSelector } from "./BranchToolbarBranchSelector";
38+
import {
39+
BranchToolbarBranchSelector,
40+
type BranchToolbarBranchSelectorHandle,
41+
} from "./BranchToolbarBranchSelector";
3942
import { BranchToolbarEnvironmentSelector } from "./BranchToolbarEnvironmentSelector";
4043
import { BranchToolbarEnvModeSelector } from "./BranchToolbarEnvModeSelector";
4144
import { Button } from "./ui/button";
@@ -57,6 +60,7 @@ import { resolveRestingComposerControlsNaturalWidth } from "./composerFooterLayo
5760
import { cn } from "~/lib/utils";
5861

5962
export interface BranchToolbarHandle {
63+
openBranchPicker: () => void;
6064
usePreviousWorktree: () => void;
6165
}
6266

@@ -478,6 +482,7 @@ export const BranchToolbar = memo(function BranchToolbar({
478482
composerControlsHostRef,
479483
contextStripVisible = true,
480484
}: BranchToolbarProps) {
485+
const branchSelectorRef = useRef<BranchToolbarBranchSelectorHandle>(null);
481486
const threadRef = useMemo(
482487
() => scopeThreadRef(environmentId, threadId),
483488
[environmentId, threadId],
@@ -541,6 +546,7 @@ export const BranchToolbar = memo(function BranchToolbar({
541546
useImperativeHandle(
542547
ref,
543548
() => ({
549+
openBranchPicker: () => branchSelectorRef.current?.open(),
544550
usePreviousWorktree: () => {
545551
if (!showGitControls || !canUsePreviousWorktree || !previousWorktreeSeed) return;
546552
onUsePreviousWorktree();
@@ -656,6 +662,7 @@ export const BranchToolbar = memo(function BranchToolbar({
656662

657663
{showGitControls ? (
658664
<BranchToolbarBranchSelector
665+
ref={branchSelectorRef}
659666
className="min-w-0 flex-initial justify-end @3xl/composer-surface:ml-auto"
660667
environmentId={environmentId}
661668
threadId={threadId}

‎apps/web/src/components/BranchToolbarBranchSelector.tsx‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import {
1515
useDeferredValue,
1616
useEffect,
1717
useId,
18+
useImperativeHandle,
1819
useLayoutEffect,
1920
useMemo,
2021
useOptimistic,
2122
useRef,
2223
useState,
2324
useTransition,
2425
type MouseEvent as ReactMouseEvent,
26+
type Ref,
2527
} from "react";
2628

2729
import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
@@ -72,7 +74,12 @@ import {
7274
import { stackedThreadToast, toastManager } from "./ui/toast";
7375
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
7476

77+
export interface BranchToolbarBranchSelectorHandle {
78+
open: () => void;
79+
}
80+
7581
interface BranchToolbarBranchSelectorProps {
82+
ref?: Ref<BranchToolbarBranchSelectorHandle>;
7683
className?: string;
7784
environmentId: EnvironmentId;
7885
threadId: ThreadId;
@@ -92,6 +99,7 @@ function toBranchActionErrorMessage(error: unknown): string {
9299
}
93100

94101
export function BranchToolbarBranchSelector({
102+
ref,
95103
className,
96104
environmentId,
97105
threadId,
@@ -535,6 +543,17 @@ export function BranchToolbarBranchSelector({
535543
}
536544
}, []);
537545

546+
useImperativeHandle(
547+
ref,
548+
() => ({
549+
open: () => {
550+
if (isInitialBranchesLoadPending || isBranchActionPending) return;
551+
handleOpenChange(true);
552+
},
553+
}),
554+
[handleOpenChange, isBranchActionPending, isInitialBranchesLoadPending],
555+
);
556+
538557
const [showTopBranchScrollFade, setShowTopBranchScrollFade] = useState(false);
539558
const [showBottomBranchScrollFade, setShowBottomBranchScrollFade] = useState(false);
540559
const fetchNextBranchPage = useCallback(() => {
@@ -777,7 +796,6 @@ export function BranchToolbarBranchSelector({
777796
// momentary 0.97 shrink would drag the open popup ~3px sideways.
778797
className="min-w-0 max-w-full font-normal text-muted-foreground/70 text-xs! hover:text-foreground/80 active:scale-100"
779798
disabled={isInitialBranchesLoadPending || isBranchActionPending}
780-
data-composer-shortcut="composer.branch"
781799
>
782800
<GitBranchIcon className="size-3 shrink-0 opacity-70" />
783801
<span

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6467,15 +6467,21 @@ export default function ChatView(props: ChatViewProps) {
64676467
command === "composer.host" ||
64686468
command === "composer.effort" ||
64696469
command === "composer.mode" ||
6470-
command === "composer.workspace" ||
6471-
command === "composer.branch"
6470+
command === "composer.workspace"
64726471
) {
64736472
event.preventDefault();
64746473
event.stopPropagation();
64756474
if (!event.repeat) composerRef.current?.openControl(command);
64766475
return;
64776476
}
64786477

6478+
if (command === "composer.branch") {
6479+
event.preventDefault();
6480+
event.stopPropagation();
6481+
if (!event.repeat) branchToolbarRef.current?.openBranchPicker();
6482+
return;
6483+
}
6484+
64796485
if (command === "composer.previousWorktree") {
64806486
event.preventDefault();
64816487
event.stopPropagation();

0 commit comments

Comments
 (0)