Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: draw one drop line per gap when dragging sidebar rows (#11942)

Michael Han901d9fd45ef0
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsx
index 4310f5e7747..3254acc1e19 100644
--- a/studio/frontend/src/components/app-sidebar.tsx
+++ b/studio/frontend/src/components/app-sidebar.tsx
@@ -329,15 +329,18 @@ const SELECT_WITH_META =
/mac/i.test(navigator.platform || navigator.userAgent);
// Insertion line on the landing edge, drawn inside the row: a section's collapsible clips its
-// overflow, and the first and last rows are exactly where a row is dragged to.
+// overflow, and the first and last rows are exactly where a row is dragged to. A border, not a
+// filled bar: border widths snap to whole device pixels, so the line keeps one thickness at any
+// zoom or UI scale instead of rounding differently per row.
const DROP_CUE_BASE =
- "before:pointer-events-none before:absolute before:inset-x-2 before:z-10 before:h-0.5 before:rounded-full before:bg-primary before:content-['']";
+ "before:pointer-events-none before:absolute before:inset-x-2 before:z-10 before:h-0 before:border-t-[1.5px] before:border-primary before:content-['']";
const DROP_CUE_TOP = `${DROP_CUE_BASE} before:top-0`;
-const DROP_CUE_BOTTOM = `${DROP_CUE_BASE} before:bottom-0`;
-// A row dropped onto a folder or section joins it, so the whole target is tinted and outlined.
-// Kept inside the box for the same clipping reason.
+// bottom-px: on the last row, DROP_ROW_HIT's extra pixel is clipped by the list.
+const DROP_CUE_BOTTOM = `${DROP_CUE_BASE} before:bottom-px`;
+// A row dropped onto a folder or section joins it, so the whole target is tinted and outlined,
+// with the same border as the line. Kept inside the box for the same clipping reason.
const DROP_INTO_CUE =
- "before:pointer-events-none before:absolute before:inset-x-1 before:inset-y-0 before:rounded-2xl before:bg-primary/8 before:ring-1 before:ring-inset before:ring-primary/70 before:content-['']";
+ "before:pointer-events-none before:absolute before:inset-x-1 before:inset-y-0 before:rounded-2xl before:bg-primary/8 before:border-[1.5px] before:border-primary before:content-['']";
// The menu keeps a 1px gap between rows. A pointer resting on that gap would hit the section
// instead, which answers with its last slot, so each row's box reaches over the gap below it.
const DROP_ROW_HIT = "pb-px -mb-px";
@@ -355,7 +358,7 @@ function landedOrder(
// A closed section has no body to light, so its header takes the tint.
const DROP_INTO_HEADER_CUE =
- "rounded-full bg-primary/8 ring-1 ring-inset ring-primary/70";
+ "rounded-full bg-primary/8 outline-solid outline-[length:1.5px] outline-primary -outline-offset-[1.5px]";
// The sort a list is on and its setter: a reorder switches a sorted list to Manual, or the
// sort would undo the drop.
@@ -4414,7 +4417,9 @@ export function AppSidebar() {
{/* Pinned: folders and chats in one list, in the order they were dropped into. */}
{!isStudioRoute && !showTrainingRecents && pinnedRows.length > 0 && (
<Collapsible open={pinnedOpen} onOpenChange={setPinnedOpen} asChild>
- <SidebarGroup className="group/sb-section group-data-[collapsible=icon]:hidden px-0 py-0">
+ {/* While open, the next section rides up over the tail strip below, so the strip adds
+ no space. */}
+ <SidebarGroup className="group/sb-section group-data-[collapsible=icon]:hidden px-0 py-0 data-[state=open]:-mb-[calc(8px*var(--ui-space-scale,1))]">
{/* The header takes drops too: above the first row, or into a closed section. */}
<SidebarGroupLabel
className={cn(
@@ -4482,7 +4487,8 @@ export function AppSidebar() {
<SidebarMenuItem
aria-hidden
className={cn(
- "relative h-[calc(8px*var(--ui-space-scale,1))]",
+ // z-[1]: above the next section's header, which overlaps it.
+ "relative z-[1] h-[calc(8px*var(--ui-space-scale,1))]",
dropCueClass(SIDEBAR_TAIL_SCOPE, "pinned"),
)}
{...dnd.dropZoneProps({
diff --git a/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts b/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts
index b960e6c21b6..448436a8345 100644
--- a/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts
+++ b/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts
@@ -12,9 +12,12 @@ import { useCallback, useEffect, useRef, useState } from "react";
import {
dropEdgeAt,
+ equivalentDrop,
+ litRingKey,
planKey,
planSidebarDrop,
rowKey,
+ SIDEBAR_TAIL_SCOPE,
STAY,
type DropEdge,
type SidebarDragItem,
@@ -80,6 +83,40 @@ function zonesUnder(x: number, y: number): ZoneHit[] {
return hits;
}
+/** Max distance between a row's bottom and the next row's top for them to share a gap. */
+const ADJACENT_PX = 3;
+
+/** Marks the row, or section tail, a line can be drawn on with its row key, so a neighbour
+ * lookup finds it directly instead of scanning every zone. */
+const ROW_KEY_ATTR = "data-sidebar-row-key";
+
+/** The row drawn directly below or above the row, or section tail, that `key` names. Probes
+ * just past its edge, so the cost does not grow with the list. */
+function rowNextTo(key: string, side: "below" | "above"): ZoneHit | null {
+ if (typeof document === "undefined") return null;
+ const self = document.querySelector(`[${ROW_KEY_ATTR}="${CSS.escape(key)}"]`);
+ if (!self) return null;
+ const from = self.getBoundingClientRect();
+ // Rows overlap by a pixel (DROP_ROW_HIT), so step two in to land inside the neighbour.
+ const y = side === "below" ? from.bottom + 1 : from.top - 2;
+ for (const element of document.elementsFromPoint(from.left + from.width / 2, y)) {
+ if (element === self || !element.hasAttribute(ROW_KEY_ATTR)) continue;
+ const raw = element.getAttribute(DROP_ZONE_ATTR);
+ if (!raw) continue;
+ try {
+ const parsed = JSON.parse(raw) as { zone: SidebarDropZone; closed?: boolean };
+ if (!parsed.zone.row) continue;
+ const rect = element.getBoundingClientRect();
+ const gap = side === "below" ? rect.top - from.bottom : from.top - rect.bottom;
+ if (Math.abs(gap) > ADJACENT_PX) return null;
+ return { zone: parsed.zone, closed: Boolean(parsed.closed), rect };
+ } catch {
+ return null;
+ }
+ }
+ return null;
+}
+
/** The list the row scrolls while it is carried: the nearest ancestor that actually scrolls. */
function scrollerOf(element: Element | null): HTMLElement | null {
for (let node = element; node; node = node.parentElement) {
@@ -183,7 +220,32 @@ export function useSidebarDrag(options: UseSidebarDragOptions): SidebarDragApi {
dropEdgeAt(hit.rect, y),
context,
);
- if (outcome) return { hit, outcome };
+ if (!outcome) continue;
+ // One line per gap: a bottom line defers to the row below's top, and a section tail's
+ // line to the row above's bottom, when that lands the drop identically. Different drops
+ // (a folder's last chat vs the next row) keep their own lines.
+ if (outcome !== STAY && "line" in outcome.cue) {
+ const { rowKey: key, edge } = outcome.cue.line;
+ const tail = key.startsWith(`${SIDEBAR_TAIL_SCOPE}:`);
+ const next = tail
+ ? rowNextTo(key, "above")
+ : edge === "bottom"
+ ? rowNextTo(key, "below")
+ : null;
+ const alt = next
+ ? planSidebarDrop(dragged, next.zone, tail ? "bottom" : "top", context)
+ : null;
+ if (
+ alt &&
+ alt !== STAY &&
+ "line" in alt.cue &&
+ equivalentDrop(alt, outcome)
+ ) {
+ // Only the painted line moves: the original `place` is what a slow move re-aims by.
+ return { hit, outcome: { ...outcome, cue: alt.cue } };
+ }
+ }
+ return { hit, outcome };
}
return null;
},
@@ -380,11 +442,21 @@ export function useSidebarDrag(options: UseSidebarDragOptions): SidebarDragApi {
);
const dropZoneProps = useCallback(
- (zone: SidebarDropZone, zoneOptions?: { closed?: boolean }) => ({
- [DROP_ZONE_ATTR]: JSON.stringify(
- zoneOptions?.closed ? { zone, closed: true } : { zone },
- ),
- }),
+ (zone: SidebarDropZone, zoneOptions?: { closed?: boolean }) => {
+ const props: Record<string, string> = {
+ [DROP_ZONE_ATTR]: JSON.stringify(
+ zoneOptions?.closed ? { zone, closed: true } : { zone },
+ ),
+ };
+ const key =
+ zone.row && !zone.header
+ ? rowKey(zone.row.scope, zone.row.id)
+ : !zone.row && zone.blockEnd?.scope === SIDEBAR_TAIL_SCOPE
+ ? rowKey(SIDEBAR_TAIL_SCOPE, zone.blockEnd.id)
+ : null;
+ if (key) props[ROW_KEY_ATTR] = key;
+ return props;
+ },
[],
);
@@ -399,8 +471,7 @@ export function useSidebarDrag(options: UseSidebarDragOptions): SidebarDragApi {
);
const ringLit = useCallback(
- (key: string): boolean =>
- Boolean(plan && "ring" in plan.cue && plan.cue.ring === key),
+ (key: string): boolean => litRingKey(plan) === key,
[plan],
);
diff --git a/studio/frontend/src/features/chat/lib/sidebar-drag.ts b/studio/frontend/src/features/chat/lib/sidebar-drag.ts
index 34b5251ef4a..e2806ebd95f 100644
--- a/studio/frontend/src/features/chat/lib/sidebar-drag.ts
+++ b/studio/frontend/src/features/chat/lib/sidebar-drag.ts
@@ -498,6 +498,34 @@ function reorder(
};
}
+/** The folder or section to outline. A drop that files the chat into a folder lights that folder
+ * even while a line shows its slot, so "into the folder" never reads as "under it". */
+export function litRingKey(plan: SidebarDropPlan | null): string | null {
+ if (!plan) return null;
+ if ("ring" in plan.cue) return plan.cue.ring;
+ if (plan.action.kind === "move" && plan.action.projectId) {
+ return folderRingKey(plan.action.projectId);
+ }
+ return null;
+}
+
+/** Whether two plans land the row identically. `place` is ignored: it names the same slot
+ * from different neighbours. */
+export function equivalentDrop(a: SidebarDropPlan, b: SidebarDropPlan): boolean {
+ const landing = (plan: SidebarDropPlan) =>
+ JSON.stringify({
+ action: plan.action,
+ orders: plan.effects.orders.map(({ scope, ids }) => ({ scope, ids })),
+ pinChat: plan.effects.pinChat,
+ unpinChat: plan.effects.unpinChat,
+ pinProject: plan.effects.pinProject,
+ unpinProject: plan.effects.unpinProject,
+ moveChat: plan.effects.moveChat,
+ switchSort: plan.effects.switchSort,
+ });
+ return landing(a) === landing(b);
+}
+
/** Changes exactly when the painted state does, so equal plans skip a re-render. */
export function planKey(plan: SidebarDropPlan | null): string {
if (!plan) return "";
diff --git a/studio/frontend/tests/sidebar-row-drag.test.ts b/studio/frontend/tests/sidebar-row-drag.test.ts
index 193ec404943..f3dcba09dae 100644
--- a/studio/frontend/tests/sidebar-row-drag.test.ts
+++ b/studio/frontend/tests/sidebar-row-drag.test.ts
@@ -9,7 +9,9 @@ import test from "node:test";
import {
dropEdgeAt,
+ equivalentDrop,
folderRingKey,
+ litRingKey,
planKey,
planSidebarDrop,
rowKey,
@@ -847,7 +849,8 @@ test("the gesture is pointer events, not the HTML5 drag API", () => {
test("a cue over nothing is cleared without trusting dragleave", () => {
assert.match(HOOK, /for \(const element of document\.elementsFromPoint\(x, y\)\)/);
// No answer here lets the zone around it answer instead.
- assert.match(HOOK, /if \(outcome\) return \{ hit, outcome \};\n\s*\}\n\s*return null;/);
+ assert.match(HOOK, /if \(!outcome\) continue;/);
+ assert.match(HOOK, /return \{ hit, outcome \};\n\s*\}\n\s*return null;/);
assert.match(
HOOK,
/if \(!aimed \|\| aimed\.outcome === STAY\) \{\n\s*\/\/[^\n]*\n\s*cancelSpring\(\);\n\s*showPlan\(null\);\n\s*return;\n\s*\}/,
@@ -903,10 +906,12 @@ test("rows cover the gap between them, so the section never answers for it", ()
test("every drop cue is drawn inside its row", () => {
for (const cue of [
"${DROP_CUE_BASE} before:top-0",
- "${DROP_CUE_BASE} before:bottom-0",
+ // A pixel up: the last row's extra hit pixel is clipped by the list.
+ "${DROP_CUE_BASE} before:bottom-px",
"before:inset-x-1 before:inset-y-0 ",
- // A ring is drawn outside its box unless inset, and the first row's box ends at the clip.
- "before:ring-1 before:ring-inset",
+ // Borders, which snap to whole device pixels, so every cue keeps one thickness.
+ "before:h-0 before:border-t-[1.5px] before:border-primary",
+ "before:border-[1.5px] before:border-primary",
]) {
assert.ok(APP_SIDEBAR.includes(cue), `no cue is drawn at ${cue}`);
}
@@ -1089,6 +1094,14 @@ test("a sort picked while a move is in flight is not overwritten", () => {
// A folder last in Pinned runs its block to the bottom of the section, so every pixel below its
// title is inside it and a chat aimed past the folder was filed into it. There was no "after".
+test("the Pinned tail strip adds no space under the section", () => {
+ // The next section rides up over it while Pinned is open.
+ assert.match(
+ APP_SIDEBAR,
+ /<SidebarGroup className="[^"]*data-\[state=open\]:-mb-\[calc\(8px\*var\(--ui-space-scale,1\)\)\]"/,
+ );
+});
+
test("a chat can be dropped after a folder that ends the Pinned list", () => {
const workScope = projectOrderScope("work");
const ctx = context({
@@ -1170,7 +1183,7 @@ test("a chat can be dropped after a folder that ends the Pinned list", () => {
assert.ok(pinnedMenu.length > 0, "the Pinned section moved");
assert.match(
pinnedMenu,
- /<SidebarMenuItem\n\s*aria-hidden\n\s*className=\{cn\(\n\s*"relative h-\[calc\(8px\*var\(--ui-space-scale,1\)\)\]",\n\s*dropCueClass\(SIDEBAR_TAIL_SCOPE, "pinned"\),/,
+ /<SidebarMenuItem\n\s*aria-hidden\n\s*className=\{cn\(\n\s*\/\/[^\n]*\n\s*"relative z-\[1\] h-\[calc\(8px\*var\(--ui-space-scale,1\)\)\]",\n\s*dropCueClass\(SIDEBAR_TAIL_SCOPE, "pinned"\),/,
);
assert.ok(
!/draggingRow && /.test(pinnedMenu),
@@ -1311,3 +1324,90 @@ test("a chat can be dropped at the bottom of a pinned project", () => {
STAY,
);
});
+
+test("the two edges of one gap are one drop, and draw one line", () => {
+ const ctx = context({
+ orders: { ...context().orders, recents: ["r1", "r2", "r3"] },
+ });
+ const drag = chat("r3", "recents", RECENTS_ORDER_SCOPE, null);
+ const underR1 = plannedDrop(
+ planSidebarDrop(drag, chatRow("recents", RECENTS_ORDER_SCOPE, "r1"), "bottom", ctx),
+ );
+ const overR2 = plannedDrop(
+ planSidebarDrop(drag, chatRow("recents", RECENTS_ORDER_SCOPE, "r2"), "top", ctx),
+ );
+ // Two cues, one landing.
+ assert.notDeepEqual(underR1.cue, overR2.cue);
+ assert.ok(equivalentDrop(underR1, overR2));
+
+ // A folder's last chat and the next folder are different drops.
+ const homeScope = projectOrderScope("home");
+ const intoHome = plannedDrop(
+ planSidebarDrop(
+ drag,
+ {
+ ...chatRow("projects", homeScope, "c3", "home", { index: 0, count: 1 }),
+ blockEnd: { scope: homeScope, id: "c3" },
+ },
+ "bottom",
+ ctx,
+ ),
+ );
+ const overMisc = plannedDrop(
+ planSidebarDrop(drag, folderRow("projects", PROJECT_ORDER_SCOPE, "misc"), "top", ctx),
+ );
+ assert.ok(!equivalentDrop(intoHome, overMisc));
+
+ // Pinned's tail and its last chat's bottom edge both land last: one drop.
+ const pinnedCtx = context({
+ pinnedChatIds: new Set(["p1", "p2", "p3"]),
+ orders: { ...context().orders, pinned: ["p1", "p2", "p3"] },
+ });
+ const pinnedDrag = chat("p1", "pinned", PINNED_ORDER_SCOPE, null);
+ const tail = plannedDrop(
+ planSidebarDrop(
+ pinnedDrag,
+ { section: "pinned", blockEnd: { scope: SIDEBAR_TAIL_SCOPE, id: "pinned" } },
+ "bottom",
+ pinnedCtx,
+ ),
+ );
+ const underLast = plannedDrop(
+ planSidebarDrop(pinnedDrag, chatRow("pinned", PINNED_ORDER_SCOPE, "p3"), "bottom", pinnedCtx),
+ );
+ assert.notDeepEqual(tail.cue, underLast.cue);
+ assert.ok(equivalentDrop(tail, underLast));
+
+ // The hook only swaps lines for equivalent drops.
+ assert.match(
+ HOOK,
+ /planSidebarDrop\(dragged, next\.zone, tail \? "bottom" : "top", context\)/,
+ );
+ assert.match(HOOK, /equivalentDrop\(alt, outcome\)/);
+ // Only the cue is swapped: the original effects keep the `place` a slow move re-aims by.
+ assert.match(HOOK, /outcome: \{ \.\.\.outcome, cue: alt\.cue \}/);
+ // Neighbours are found by key and a point probe, not by scanning every zone per frame.
+ assert.match(HOOK, /document\.querySelector\(`\[\$\{ROW_KEY_ATTR\}="\$\{CSS\.escape\(key\)\}"\]`\)/);
+ assert.doesNotMatch(HOOK, /querySelectorAll\(`\[\$\{DROP_ZONE_ATTR\}\]`\)/);
+});
+
+test("a drop into a folder lights the folder, even while a line shows the slot", () => {
+ const ctx = context();
+ const drag = chat("r1", "recents", RECENTS_ORDER_SCOPE, null);
+ const homeScope = projectOrderScope("home");
+ const slotted = plannedDrop(
+ planSidebarDrop(drag, chatRow("projects", homeScope, "c3", "home", { index: 0, count: 1 }), "top", ctx),
+ );
+ assert.deepEqual(slotted.action, { kind: "move", projectId: "home" });
+ assert.ok("line" in slotted.cue);
+ assert.equal(litRingKey(slotted), folderRingKey("home"));
+
+ // A reorder within Recents files nothing, so nothing is lit.
+ const ctxRecents = context({ orders: { ...context().orders, recents: ["r1", "r2", "r3"] } });
+ const reorder = plannedDrop(
+ planSidebarDrop(chat("r3", "recents", RECENTS_ORDER_SCOPE, null), chatRow("recents", RECENTS_ORDER_SCOPE, "r1"), "top", ctxRecents),
+ );
+ assert.equal(litRingKey(reorder), null);
+ assert.equal(litRingKey(null), null);
+ assert.match(HOOK, /\(key: string\): boolean => litRingKey\(plan\) === key/);
+});