Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions apps/web/src/components/BranchToolbarBranchSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ export function BranchToolbarBranchSelector({
setIsBranchMenuOpen(open);
if (!open) {
setBranchQuery("");
highlightedBranchValueRef.current = null;
}
}, []);

Expand Down Expand Up @@ -594,6 +595,9 @@ export function BranchToolbarBranchSelector({
}, [fetchNextBranchPage, hasNextPage, isBranchMenuOpen, isFetchingNextPage]);

const branchListRef = useRef<LegendListRef | null>(null);
// Tracks the highlighted picker value so Enter can activate it even when the
// virtualized row is not mounted (Base UI Enter clicks the mounted element).
const highlightedBranchValueRef = useRef<string | null>(null);
const updateBranchListScrollFades = useCallback(() => {
const scrollElement = branchListRef.current?.getScrollableNode?.();
if (!(scrollElement instanceof HTMLElement)) {
Expand Down Expand Up @@ -676,6 +680,20 @@ export function BranchToolbarBranchSelector({
const prUrl = currentLinkedPr?.url ?? displayedPr?.url;
const openPrLink = useOpenPrLink(threadRef);

function selectPickerItem(itemValue: string) {
highlightedBranchValueRef.current = null;
if (itemValue === checkoutPullRequestItemValue && prReference && onCheckoutPullRequestRequest) {
handleOpenChange(false);
onComposerFocusRequest?.();
onCheckoutPullRequestRequest(prReference);
} else if (itemValue === createBranchItemValue) {
createRef(trimmedBranchQuery);
} else {
const refName = branchByName.get(itemValue);
if (refName) selectBranch(refName);
}
}

function renderPickerItem(itemValue: string, index: number) {
if (checkoutPullRequestItemValue && itemValue === checkoutPullRequestItemValue) {
return (
Expand All @@ -685,15 +703,7 @@ export function BranchToolbarBranchSelector({
index={index}
value={itemValue}
className="pe-2"
onClick={() => {
if (!prReference || !onCheckoutPullRequestRequest) {
return;
}
setIsBranchMenuOpen(false);
setBranchQuery("");
onComposerFocusRequest?.();
onCheckoutPullRequestRequest(prReference);
}}
onClick={() => selectPickerItem(itemValue)}
>
<div className="flex min-w-0 items-center gap-2 py-1">
<SourceControlIcon className="size-3.5 shrink-0 text-muted-foreground" />
Expand All @@ -715,7 +725,7 @@ export function BranchToolbarBranchSelector({
index={index}
value={itemValue}
className="pe-1.5"
onClick={() => createRef(trimmedBranchQuery)}
onClick={() => selectPickerItem(itemValue)}
>
<span className="truncate">Create new ref &quot;{newRefName}&quot;</span>
</ComboboxItem>
Expand Down Expand Up @@ -743,7 +753,7 @@ export function BranchToolbarBranchSelector({
index={index}
value={itemValue}
className="pe-1.5"
onClick={() => selectBranch(refName)}
onClick={() => selectPickerItem(itemValue)}
onContextMenu={(event) => handleBranchContextMenu(event, itemValue)}
>
<div className="flex w-full min-w-0 items-center justify-between gap-2">
Expand All @@ -760,7 +770,8 @@ export function BranchToolbarBranchSelector({
filteredItems={filteredBranchPickerItems}
autoHighlight
virtualized
onItemHighlighted={(_value, eventDetails) => {
onItemHighlighted={(value, eventDetails) => {
highlightedBranchValueRef.current = typeof value === "string" ? value : null;
if (!isBranchMenuOpen || eventDetails.index < 0 || eventDetails.reason !== "keyboard") {
return;
}
Expand Down Expand Up @@ -828,6 +839,24 @@ export function BranchToolbarBranchSelector({
placeholder="Search refs..."
value={branchQuery}
onChange={(event) => setBranchQuery(event.target.value)}
onKeyDown={(event) => {
if (event.key !== "Enter" || event.nativeEvent.isComposing || event.keyCode === 229) {
return;
}
const highlightedValue = highlightedBranchValueRef.current;
if (
highlightedValue === null ||
!filteredBranchPickerItems.includes(highlightedValue)
) {
return;
}
(
event as typeof event & { preventBaseUIHandler?: () => void }
).preventBaseUIHandler?.();
event.preventDefault();
event.stopPropagation();
selectPickerItem(highlightedValue);
}}
/>
<div className="flex min-h-0 flex-1 flex-col overflow-hidden">
<ComboboxEmpty>No refs found.</ComboboxEmpty>
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/components/PullRequestThreadDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,12 @@ export function PullRequestThreadDialog({
if (event.key !== "Enter") {
return;
}
if (event.nativeEvent.isComposing || event.keyCode === 229) {
return;
}
event.preventDefault();
if (!isResolving && !preparePullRequestThreadAction.isPending) {
void handleConfirm("local");
void handleConfirm("worktree");
}
}}
/>
Expand Down
Loading