Skip to content

Commit ecea300

Browse files
root-daemonclaudemaria-rcks
authored
fix(web): sidebar search results can be dragged onto the composer (pingdotgg#28016)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 7875604 commit ecea300

2 files changed

Lines changed: 73 additions & 52 deletions

File tree

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

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
10421042
const [renamingTitle, setRenamingTitle] = useState("");
10431043
const settlingThreadKeysRef = useRef(new Set<string>());
10441044
const threadListRef = useRef<HTMLUListElement | null>(null);
1045+
const searchResultsListRef = useRef<HTMLUListElement | null>(null);
10451046
const sidebarContentRef = useRef<HTMLDivElement | null>(null);
10461047
const dragLabelOffsetRef = useRef(0);
10471048
const listMotionRef = useRef<ReturnType<typeof createSidebarListMotion> | null>(null);
@@ -1738,7 +1739,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
17381739
});
17391740
};
17401741
const pointerOutsideThreadList = (point: { x: number; y: number }) => {
1741-
const bounds = threadListRef.current?.getBoundingClientRect();
1742+
// Search results replace the thread list, so only one of them is mounted.
1743+
const bounds = (threadListRef.current ?? searchResultsListRef.current)?.getBoundingClientRect();
17421744
return bounds !== undefined && (point.x < bounds.left || point.x > bounds.right);
17431745
};
17441746
// The path out of the list often crosses dnd-kit's edge zone, which autoscrolls the sidebar.
@@ -3225,57 +3227,66 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
32253227
closeDelay={0}
32263228
timeout={400}
32273229
>
3228-
<ul
3229-
id="sidebar-thread-search-results"
3230-
role="listbox"
3231-
aria-label="Thread search results"
3232-
className="flex flex-col gap-px"
3230+
<DndContext
3231+
sensors={dndSensors}
3232+
autoScroll={false}
3233+
onDragStart={(event) => {
3234+
contextDragKeyRef.current = String(event.active.id);
3235+
}}
32333236
>
3234-
{threadSearchResults.map((thread, index) => {
3235-
const threadKey = scopedThreadKey(
3236-
scopeThreadRef(thread.environmentId, thread.id),
3237-
);
3238-
return (
3239-
<SidebarSearchResultRow
3240-
isSettled={settledThreadKeys.has(threadKey)}
3241-
key={threadKey}
3242-
thread={thread}
3243-
project={
3244-
projectByKey.get(`${thread.environmentId}:${thread.projectId}`) ?? null
3245-
}
3246-
projectDisplayName={
3247-
projectDisplayNameByKey.get(
3248-
`${thread.environmentId}:${thread.projectId}`,
3249-
) ?? null
3250-
}
3251-
environmentLabel={environmentLabelById.get(thread.environmentId) ?? null}
3252-
environmentMachine={
3253-
environmentMachineById.get(thread.environmentId) ?? "server"
3254-
}
3255-
providerEntryByInstanceId={
3256-
providerEntriesByEnvironment.get(thread.environmentId) ??
3257-
EMPTY_PROVIDER_ENTRIES
3258-
}
3259-
isHighlighted={activeSearchResultIndex === index}
3260-
isRouteActive={routeRowThreadKey === threadKey}
3261-
resultId={threadSearchResultId(index)}
3262-
searchMatch={
3263-
threadSearchMatchByKey.get(
3264-
threadSearchMatchKey({
3265-
environmentId: thread.environmentId,
3266-
threadId: thread.id,
3267-
}),
3268-
) ?? null
3269-
}
3270-
searchQuery={threadSearchQuery}
3271-
searchMatchQuery={threadSearch.query}
3272-
onHighlight={() => setActiveSearchResultIndex(index)}
3273-
onSelect={() => selectThreadSearchResult(thread)}
3274-
onFileDropThreads={handleThreadFileDrop}
3275-
/>
3276-
);
3277-
})}
3278-
</ul>
3237+
<ul
3238+
ref={searchResultsListRef}
3239+
id="sidebar-thread-search-results"
3240+
role="listbox"
3241+
aria-label="Thread search results"
3242+
className="flex flex-col gap-px"
3243+
>
3244+
{threadSearchResults.map((thread, index) => {
3245+
const threadKey = scopedThreadKey(
3246+
scopeThreadRef(thread.environmentId, thread.id),
3247+
);
3248+
return (
3249+
<SidebarSearchResultRow
3250+
isSettled={settledThreadKeys.has(threadKey)}
3251+
key={threadKey}
3252+
thread={thread}
3253+
project={
3254+
projectByKey.get(`${thread.environmentId}:${thread.projectId}`) ?? null
3255+
}
3256+
projectDisplayName={
3257+
projectDisplayNameByKey.get(
3258+
`${thread.environmentId}:${thread.projectId}`,
3259+
) ?? null
3260+
}
3261+
environmentLabel={environmentLabelById.get(thread.environmentId) ?? null}
3262+
environmentMachine={
3263+
environmentMachineById.get(thread.environmentId) ?? "server"
3264+
}
3265+
providerEntryByInstanceId={
3266+
providerEntriesByEnvironment.get(thread.environmentId) ??
3267+
EMPTY_PROVIDER_ENTRIES
3268+
}
3269+
isHighlighted={activeSearchResultIndex === index}
3270+
isRouteActive={routeRowThreadKey === threadKey}
3271+
resultId={threadSearchResultId(index)}
3272+
searchMatch={
3273+
threadSearchMatchByKey.get(
3274+
threadSearchMatchKey({
3275+
environmentId: thread.environmentId,
3276+
threadId: thread.id,
3277+
}),
3278+
) ?? null
3279+
}
3280+
searchQuery={threadSearchQuery}
3281+
searchMatchQuery={threadSearch.query}
3282+
onHighlight={() => setActiveSearchResultIndex(index)}
3283+
onSelect={() => selectThreadSearchResult(thread)}
3284+
onFileDropThreads={handleThreadFileDrop}
3285+
/>
3286+
);
3287+
})}
3288+
</ul>
3289+
</DndContext>
32793290
</TooltipProvider>
32803291
) : (
32813292
<p

‎apps/web/src/components/sidebar/SidebarThreadRow.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { requestCustomSnooze } from "../CustomSnoozeDialog";
66
import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";
77
import { useDeadlinePassed } from "~/hooks/useDeadline";
88
import { resolveThreadCurrentPullRequestLink } from "@t3tools/client-runtime/thread-pull-requests";
9+
import { useDraggable } from "@dnd-kit/core";
910
import { useSortable } from "@dnd-kit/sortable";
1011
import { CSS } from "@dnd-kit/utilities";
1112
import {
@@ -1642,9 +1643,17 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
16421643
isActive: props.isRouteActive,
16431644
});
16441645
const threadRef = scopeThreadRef(thread.environmentId, thread.id);
1645-
const { leaseLiveStatus, rowRef } = useSidebarRowSubscriptionLease(
1646+
// Results only drag out as chat context; the row keeps its own listbox attributes.
1647+
const { listeners: dragListeners, setNodeRef: setDragNodeRef } = useDraggable({
1648+
id: scopedThreadKey(threadRef),
1649+
});
1650+
const { leaseLiveStatus, rowRef: leaseRowRef } = useSidebarRowSubscriptionLease(
16461651
props.isHighlighted || props.isRouteActive,
16471652
);
1653+
const rowRef = (row: HTMLElement | null) => {
1654+
setDragNodeRef(row);
1655+
return leaseRowRef(row);
1656+
};
16481657
const gitCwd = thread.worktreePath ?? props.project?.workspaceRoot ?? null;
16491658
const branchTarget =
16501659
leaseLiveStatus && (thread.branch != null || thread.worktreePath !== null) && gitCwd !== null
@@ -1714,6 +1723,7 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
17141723
aria-current={accessibility.current}
17151724
aria-describedby={`${props.resultId}-pr`}
17161725
aria-label={accessibility.label}
1726+
{...dragListeners}
17171727
onMouseMove={props.onHighlight}
17181728
onClick={props.onSelect}
17191729
className={cn(

0 commit comments

Comments
 (0)