Skip to content
Merged
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
11 changes: 11 additions & 0 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
} | null>(null);
const dragSensorRef = useRef<SidebarPointerSensor | null>(null);
const contextDragKeyRef = useRef<string | null>(null);
const dragScrollRef = useRef<{ readonly viewport: Element; readonly top: number } | null>(null);
const [actionSweep, setActionSweep] = useState<{
action: SidebarSweepAction;
keys: ReadonlySet<string>;
Expand Down Expand Up @@ -1713,6 +1714,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
const finishThreadDrag = (started: boolean) => {
dragSensorRef.current = null;
contextDragKeyRef.current = null;
dragScrollRef.current = null;
endThreadContextDrag();
if (started) {
listMotionRef.current?.release();
Expand All @@ -1739,6 +1741,11 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
const bounds = threadListRef.current?.getBoundingClientRect();
return bounds !== undefined && (point.x < bounds.left || point.x > bounds.right);
};
// The path out of the list often crosses dnd-kit's edge zone, which autoscrolls the sidebar.
const restoreDragScroll = () => {
const scroll = dragScrollRef.current;
if (scroll && scroll.viewport.scrollTop !== scroll.top) scroll.viewport.scrollTop = scroll.top;
};
const moveThreadContextDrag = (point: { x: number; y: number }) => {
const contextDrag = pointerOutsideThreadList(point);
setDragState((current) =>
Expand All @@ -1750,6 +1757,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
endThreadContextDrag();
return false;
}
restoreDragScroll();
const threads = contextDragThreads();
const title =
threadByKeyRef.current.get(contextDragKeyRef.current ?? "")?.title.trim() || "Thread";
Expand All @@ -1758,6 +1766,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
};
const dropThreadContextDrag = (point: { x: number; y: number }) => {
if (!pointerOutsideThreadList(point)) return false;
restoreDragScroll();
dropThreadContext(point, contextDragThreads());
return true;
};
Expand Down Expand Up @@ -1884,6 +1893,8 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
if (activeSection === undefined) return;
listMotionRef.current?.suspend();
const list = threadListRef.current;
const viewport = list?.closest('[data-slot="scroll-area-viewport"]');
dragScrollRef.current = viewport ? { viewport, top: viewport.scrollTop } : null;
const header = list?.querySelector<HTMLElement>('[data-testid="sidebar-pinned-header"]');
if (list && header) {
const listRect = list.getBoundingClientRect();
Expand Down
Loading