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: drag to reorder pinned models in the model picker (#11941)

Michael Han454ecb80ba92
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index a843ab06770..beb4b662689 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -136,7 +136,12 @@ export {
type SidebarDropZone,
type SidebarSection,
} from "./lib/sidebar-drag";
-export { useSidebarDrag, SPRING_OPEN_DELAY_MS } from "./hooks/use-sidebar-drag";
+export {
+ useSidebarDrag,
+ SPRING_OPEN_DELAY_MS,
+ DRAG_THRESHOLD_PX,
+ DRAGGING_BODY_CLASS,
+} from "./hooks/use-sidebar-drag";
export { usePinnedChatsStore } from "./stores/pinned-chats-store";
export { usePinnedProjectsStore } from "./stores/pinned-projects-store";
export {
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx b/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
index dd73500f4fd..8e848177af7 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
+++ b/studio/frontend/src/features/model-picker/components/model-selector/pickers.tsx
@@ -188,10 +188,12 @@ import {
import { usePinnedConnectedModelsStore } from "./pinned-connected-models";
import {
makePinRank,
+ pinDropAnchor,
pinKey,
pinnedQuantEntries,
usePinnedModelsStore,
} from "./pinned-models";
+import { usePinnedRowDrag, type PinnedDropEdge } from "./use-pinned-row-drag";
import {
type FormatFilter,
estimateQuantBytes,
@@ -964,6 +966,14 @@ const META_COLUMN = {
const ROW_ACTIONS_CLASS =
"mr-0.5 flex w-[calc(38px*var(--ui-space-scale,1))] shrink-0 items-center justify-end -space-x-0.5 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100 group-focus-within:opacity-100 has-[[data-state=open]]:opacity-100 [@media(hover:none)]:opacity-100";
+// Drop line for a pinned-row drag, same as the sidebar's.
+const PINNED_DROP_CUE_BASE =
+ "before:pointer-events-none before:absolute before:inset-x-2 before:z-10 before:h-[1.5px] before:rounded-full before:bg-primary before:content-['']";
+const PINNED_DROP_CUE: Record<PinnedDropEdge, string> = {
+ top: `${PINNED_DROP_CUE_BASE} before:top-0`,
+ bottom: `${PINNED_DROP_CUE_BASE} before:bottom-0`,
+};
+
// Partial rows keep their buttons on screen. Everywhere else the gutter hides until hover because
// the row itself is the action, but a partial cannot be loaded at all: the menu IS its only
// affordance, and hiding it reads as the stalled download having no controls.
@@ -4414,20 +4424,6 @@ export function HubModelPicker({
const togglePinnedConnected = usePinnedConnectedModelsStore(
(s) => s.togglePinnedConnected,
);
- const movePinnedConnected = usePinnedConnectedModelsStore(
- (s) => s.movePinnedConnected,
- );
- const beginPinnedConnectedDrag = usePinnedConnectedModelsStore(
- (s) => s.beginPinnedConnectedDrag,
- );
- const endPinnedConnectedDrag = usePinnedConnectedModelsStore(
- (s) => s.endPinnedConnectedDrag,
- );
- // The id under the cursor mid-drag. A ref, not state: dragenter fires on every row crossed.
- const draggingPinnedConnectedRef = useRef<string | null>(null);
- const [draggingPinnedConnectedId, setDraggingPinnedConnectedId] = useState<
- string | null
- >(null);
const pinnedConnectedSet = useMemo(
() => new Set(pinnedConnectedIds),
[pinnedConnectedIds],
@@ -4904,6 +4900,33 @@ export function HubModelPicker({
.sort((a, b) => rank(a.id) - rank(b.id));
}, [connectedMatches, pinnedConnectedIds, pinnedConnectedSet]);
+ // Drag to reorder both Pinned groups. Drops go through the stores' drag session so they
+ // persist once.
+ const pinnedDrag = usePinnedRowDrag({
+ scope: "on-device",
+ order: () => pinnedRows.map((row) => row.key),
+ onDrop: (fromKey, drop) => {
+ const store = usePinnedModelsStore.getState();
+ const anchor = pinDropAnchor(store.pinned, fromKey, drop.key, drop.edge);
+ if (!anchor) return;
+ store.beginPinnedDrag();
+ store.movePinned(fromKey, anchor);
+ store.endPinnedDrag(true);
+ },
+ });
+ const pinnedConnectedDrag = usePinnedRowDrag({
+ scope: "connected",
+ order: () => pinnedConnectedRows.map((model) => model.id),
+ onDrop: (fromId, drop) => {
+ const store = usePinnedConnectedModelsStore.getState();
+ const anchor = pinDropAnchor(store.pinned, fromId, drop.key, drop.edge);
+ if (!anchor) return;
+ store.beginPinnedConnectedDrag();
+ store.movePinnedConnected(fromId, anchor);
+ store.endPinnedConnectedDrag(true);
+ },
+ });
+
const connectedGroups = useMemo(() => {
const byProvider = new Map<
string,
@@ -5467,12 +5490,29 @@ export function HubModelPicker({
selected && "bg-sidebar-accent",
);
+ // A draggable Pinned row: faded while carried, lined where it would land.
+ const renderPinnedDragRow = (
+ drag: ReturnType<typeof usePinnedRowDrag>,
+ key: string,
+ row: ReactNode,
+ ) => {
+ const edge = drag.lineEdge(key);
+ return (
+ <div
+ key={key}
+ {...drag.rowProps(key)}
+ className={cn("relative", edge && PINNED_DROP_CUE[edge])}
+ style={drag.draggingKey === key ? { opacity: 0.4 } : undefined}
+ >
+ {row}
+ </div>
+ );
+ };
+
// One connected model, through ModelRow like every On Device row, so the badges and the hover
// gutter are the same components rather than a second set that drifts.
const renderConnectedModelRow = (
model: ExternalModelOption,
- // Only pinned rows drag: the groups below are sorted, so a drop there could not be honoured.
- draggable = false,
// No heading above this row to name its connection: the pinned group, and the flat list the
// name sort produces. Two connections can serve one model id, so the row has to say.
headless = false,
@@ -5499,61 +5539,6 @@ export function HubModelPicker({
// it takes the pill's left edge leftward rather than moving the name off that label.
// The reserved leading slot used to put 23.5px of empty pill in front of every name.
className={cn(downloadedRowShellClassName(isSelected), "ml-4")}
- style={
- draggingPinnedConnectedId === model.id ? { opacity: 0.4 } : undefined
- }
- draggable={draggable}
- onDragStart={
- draggable
- ? (event) => {
- event.dataTransfer.effectAllowed = "move";
- // Firefox will not start a drag without data.
- event.dataTransfer.setData("text/plain", model.id);
- draggingPinnedConnectedRef.current = model.id;
- setDraggingPinnedConnectedId(model.id);
- // Reordering is live on dragenter; this is what a cancelled drag rolls back to.
- beginPinnedConnectedDrag();
- }
- : undefined
- }
- onDragEnd={
- draggable
- ? () => {
- draggingPinnedConnectedRef.current = null;
- setDraggingPinnedConnectedId(null);
- // Escape, or a release off-row, reaches dragend without a drop. After a drop the
- // session is already committed and cleared, so this is a no-op.
- endPinnedConnectedDrag(false);
- }
- : undefined
- }
- onDragOver={
- draggable
- ? (event) => {
- if (draggingPinnedConnectedRef.current) event.preventDefault();
- }
- : undefined
- }
- onDragEnter={
- draggable
- ? () => {
- const dragId = draggingPinnedConnectedRef.current;
- if (dragId && dragId !== model.id) {
- movePinnedConnected(dragId, model.id);
- }
- }
- : undefined
- }
- onDrop={
- draggable
- ? (event) => {
- event.preventDefault();
- draggingPinnedConnectedRef.current = null;
- setDraggingPinnedConnectedId(null);
- endPinnedConnectedDrag(true);
- }
- : undefined
- }
>
<div className="min-w-0 flex-1">
<ModelRow
@@ -6346,7 +6331,11 @@ export function HubModelPicker({
{pinnedConnectedCollapsed
? null
: pinnedConnectedRows.map((model) =>
- renderConnectedModelRow(model, true, true),
+ renderPinnedDragRow(
+ pinnedConnectedDrag,
+ model.id,
+ renderConnectedModelRow(model, true),
+ ),
)}
</div>
) : null}
@@ -6383,7 +6372,7 @@ export function HubModelPicker({
{collapsed
? null
: group.models.map((model) =>
- renderConnectedModelRow(model, false, !headed),
+ renderConnectedModelRow(model, !headed),
)}
</div>
);
@@ -6435,9 +6424,13 @@ export function HubModelPicker({
</ListLabel>
{!pinnedCollapsed &&
pinnedRows.map((row) =>
- row.entry
- ? renderPinnedQuantRow(row.entry)
- : renderDownloadedModelRow(row.model),
+ renderPinnedDragRow(
+ pinnedDrag,
+ row.key,
+ row.entry
+ ? renderPinnedQuantRow(row.entry)
+ : renderDownloadedModelRow(row.model),
+ ),
)}
</>
) : null}
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/pinned-models.ts b/studio/frontend/src/features/model-picker/components/model-selector/pinned-models.ts
index d6d8c9baff0..13e389c7579 100644
--- a/studio/frontend/src/features/model-picker/components/model-selector/pinned-models.ts
+++ b/studio/frontend/src/features/model-picker/components/model-selector/pinned-models.ts
@@ -27,6 +27,30 @@ export function makePinRank(
return (key) => pinIndex.get(key) ?? Number.MAX_SAFE_INTEGER;
}
+/**
+ * The key to `movePinned` onto so `fromKey` lands on `edge` of `targetKey`, or null if nothing
+ * moves. `movePinned` takes the target's slot, so the other edge aims at the neighbour.
+ */
+export function pinDropAnchor(
+ pinned: readonly string[],
+ fromKey: string,
+ targetKey: string,
+ edge: "top" | "bottom",
+): string | null {
+ const from = pinned.indexOf(fromKey);
+ const to = pinned.indexOf(targetKey);
+ if (from < 0 || to < 0 || from === to) return null;
+ const slot =
+ from < to
+ ? edge === "bottom"
+ ? to
+ : to - 1
+ : edge === "top"
+ ? to
+ : to + 1;
+ return slot === from ? null : (pinned[slot] ?? null);
+}
+
/** The pinned GGUF quants, in pin order. Plain repo pins are excluded. */
export function pinnedQuantEntries(pinned: string[]): PinnedQuantEntry[] {
const out: PinnedQuantEntry[] = [];
diff --git a/studio/frontend/src/features/model-picker/components/model-selector/use-pinned-row-drag.ts b/studio/frontend/src/features/model-picker/components/model-selector/use-pinned-row-drag.ts
new file mode 100644
index 00000000000..56325220164
--- /dev/null
+++ b/studio/frontend/src/features/model-picker/components/model-selector/use-pinned-row-drag.ts
@@ -0,0 +1,344 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// Drag to reorder a Pinned group in the model selector, like pinned chats in the sidebar.
+// Pointer events, not HTML5 drag: the desktop webview never forwards dragover or drop.
+
+import { useCallback, useEffect, useRef, useState } from "react";
+
+import { DRAGGING_BODY_CLASS, DRAG_THRESHOLD_PX } from "@/features/chat";
+
+export type PinnedDropEdge = "top" | "bottom";
+
+/** The row's group, so two Pinned groups never swap rows. */
+const SCOPE_ATTR = "data-pinned-drop-scope";
+/** Carries the row's pin key. */
+const KEY_ATTR = "data-pinned-drop-key";
+
+/** Controls with their own press: row buttons other than the row itself, and links. */
+const NO_DRAG_SELECTOR =
+ "button:not([data-model-picker-option]), a[href], [role='menuitem']";
+
+/** How far outside a row the pointer still aims at it. */
+const NEAR_ROW_PX = 12;
+
+/** Edge auto-scroll zone and step per frame. */
+const EDGE_PX = 40;
+const EDGE_STEP_PX = 10;
+
+export interface PinnedRowDrop {
+ key: string;
+ edge: PinnedDropEdge;
+}
+
+function scrollerOf(element: Element | null): HTMLElement | null {
+ for (let node = element; node; node = node.parentElement) {
+ if (!(node instanceof HTMLElement)) continue;
+ const overflow = getComputedStyle(node).overflowY;
+ if (
+ (overflow === "auto" || overflow === "scroll") &&
+ node.scrollHeight > node.clientHeight
+ ) {
+ return node;
+ }
+ }
+ return null;
+}
+
+function edgeAt(rect: DOMRect, y: number): PinnedDropEdge {
+ return y < rect.top + rect.height / 2 ? "top" : "bottom";
+}
+
+/** The row of `scope` under the pointer, else the nearest one in reach. */
+function rowUnder(scope: string, x: number, y: number): PinnedRowDrop | null {
+ if (typeof document === "undefined") return null;
+ for (const element of document.elementsFromPoint(x, y)) {
+ const row = element.closest(`[${KEY_ATTR}]`);
+ if (!row || row.getAttribute(SCOPE_ATTR) !== scope) continue;
+ const key = row.getAttribute(KEY_ATTR);
+ if (key) return { key, edge: edgeAt(row.getBoundingClientRect(), y) };
+ }
+ let nearest: { drop: PinnedRowDrop; distance: number } | null = null;
+ for (const row of document.querySelectorAll(
+ `[${SCOPE_ATTR}="${CSS.escape(scope)}"]`,
+ )) {
+ const key = row.getAttribute(KEY_ATTR);
+ const rect = row.getBoundingClientRect();
+ if (!key || x < rect.left || x > rect.right) continue;
+ const distance =
+ y < rect.top ? rect.top - y : y > rect.bottom ? y - rect.bottom : 0;
+ if (distance > NEAR_ROW_PX) continue;
+ if (!nearest || distance < nearest.distance) {
+ nearest = { drop: { key, edge: edgeAt(rect, y) }, distance };
+ }
+ }
+ return nearest?.drop ?? null;
+}
+
+/** Whether dropping `fromKey` on this spot leaves it where it already is. */
+function staysPut(
+ order: readonly string[],
+ fromKey: string,
+ drop: PinnedRowDrop,
+): boolean {
+ const from = order.indexOf(fromKey);
+ const target = order.indexOf(drop.key);
+ if (from < 0 || target < 0) return true;
+ const slot = target + (drop.edge === "bottom" ? 1 : 0);
+ return slot === from || slot === from + 1;
+}
+
+export interface UsePinnedRowDragOptions {
+ /** Tells this group's rows apart from other groups'. */
+ scope: string;
+ /** The group's pin keys as drawn. Read at event time. */
+ order: () => readonly string[];
+ /** Lands `fromKey` on the given edge of `drop.key`. */
+ onDrop: (fromKey: string, drop: PinnedRowDrop) => void;
+}
+
+export interface PinnedRowDragApi {
+ /** The lifted row, for painting it faded. Null between drags. */
+ draggingKey: string | null;
+ /** The edge the insertion line is drawn on for this row, if any. */
+ lineEdge: (key: string) => PinnedDropEdge | undefined;
+ /** Props for a row's wrapper: pick-up, hit-test marks and Alt+arrow reorder. */
+ rowProps: (key: string) => {
+ onPointerDown: (event: React.PointerEvent) => void;
+ onKeyDownCapture: (event: React.KeyboardEvent) => void;
+ onDragStart: (event: React.DragEvent) => void;
+ [SCOPE_ATTR]: string;
+ [KEY_ATTR]: string;
+ };
+}
+
+export function usePinnedRowDrag(
+ options: UsePinnedRowDragOptions,
+): PinnedRowDragApi {
+ const [draggingKey, setDraggingKey] = useState<string | null>(null);
+ const [target, setTarget] = useState<PinnedRowDrop | null>(null);
+ // Handlers are made once and read the latest options at event time.
+ const optionsRef = useRef(options);
+ useEffect(() => {
+ optionsRef.current = options;
+ });
+ const draggingRef = useRef<string | null>(null);
+ const targetRef = useRef<PinnedRowDrop | null>(null);
+ const scroller = useRef<HTMLElement | null>(null);
+ /** The gesture in flight, so a second press cannot overlap it. */
+ const press = useRef<{ end: () => void } | null>(null);
+
+ const showTarget = useCallback((next: PinnedRowDrop | null) => {
+ const current = targetRef.current;
+ if (current?.key === next?.key && current?.edge === next?.edge) return;
+ targetRef.current = next;
+ setTarget(next);
+ }, []);
+
+ const clear = useCallback(() => {
+ draggingRef.current = null;
+ scroller.current = null;
+ document.body.classList.remove(DRAGGING_BODY_CLASS);
+ setDraggingKey(null);
+ showTarget(null);
+ }, [showTarget]);
+
+ useEffect(
+ () => () => {
+ press.current?.end();
+ },
+ [],
+ );
+
+ /** The landing spot under the pointer, or null where a drop would change nothing. */
+ const aim = useCallback((x: number, y: number): PinnedRowDrop | null => {
+ const fromKey = draggingRef.current;
+ if (!fromKey) return null;
+ const { scope, order } = optionsRef.current;
+ const drop = rowUnder(scope, x, y);
+ if (!drop) return null;
+ const keys = order();
+ if (staysPut(keys, fromKey, drop)) return null;
+ // One line per gap: a row's bottom is drawn as the next row's top.
+ const next = drop.edge === "bottom" ? keys[keys.indexOf(drop.key) + 1] : undefined;
+ return next ? { key: next, edge: "top" } : drop;
+ }, []);
+
+ const rowProps = useCallback(
+ (key: string) => ({
+ [SCOPE_ATTR]: optionsRef.current.scope,
+ [KEY_ATTR]: key,
+ // A native drag of the row's link or text would cancel the pointer stream.
+ onDragStart: (event: React.DragEvent) => event.preventDefault(),
+ onKeyDownCapture: (event: React.KeyboardEvent) => {
+ if (!event.altKey || event.shiftKey || event.metaKey || event.ctrlKey) {
+ return;
+ }
+ if (event.key !== "ArrowUp" && event.key !== "ArrowDown") return;
+ // Before the list's own arrow handling moves focus.
+ event.preventDefault();
+ event.stopPropagation();
+ const order = optionsRef.current.order();
+ const index = order.indexOf(key);
+ const up = event.key === "ArrowUp";
+ const neighbour = order[up ? index - 1 : index + 1];
+ if (index < 0 || !neighbour) return;
+ optionsRef.current.onDrop(key, {
+ key: neighbour,
+ edge: up ? "top" : "bottom",
+ });
+ // The row can lose focus on re-render; restore it.
+ const scope = optionsRef.current.scope;
+ requestAnimationFrame(() => {
+ const row = document.querySelector(
+ `[${SCOPE_ATTR}="${CSS.escape(scope)}"][${KEY_ATTR}="${CSS.escape(key)}"]`,
+ );
+ const option = row?.querySelector<HTMLElement>(
+ "[data-model-picker-option]",
+ );
+ if (option && document.activeElement !== option) option.focus();
+ });
+ },
+ onPointerDown: (event: React.PointerEvent) => {
+ // Touch scrolls the list, and the right button opens the row menu.
+ if (event.button !== 0 || event.pointerType === "touch") return;
+ if (!event.isPrimary) return;
+ if ((event.target as Element | null)?.closest?.(NO_DRAG_SELECTOR)) {
+ return;
+ }
+ // Drop a stale gesture whose release was missed, or it blocks every later drag.
+ press.current?.end();
+
+ const startX = event.clientX;
+ const startY = event.clientY;
+ const row = event.currentTarget as HTMLElement;
+ const pointerId = event.pointerId;
+ const at = { x: startX, y: startY };
+ let started = false;
+ let escaped = false;
+ let frame = 0;
+
+ const detach = () => {
+ if (press.current === self) press.current = null;
+ if (frame) cancelAnimationFrame(frame);
+ frame = 0;
+ window.removeEventListener("pointermove", onMove);
+ window.removeEventListener("pointerup", onUp);
+ window.removeEventListener("pointercancel", onCancel);
+ window.removeEventListener("keydown", onKey, true);
+ if (document.body.hasPointerCapture?.(pointerId)) {
+ document.body.releasePointerCapture(pointerId);
+ }
+ };
+ // Re-aim every frame: the list can scroll under a resting pointer.
+ const onFrame = () => {
+ if (!draggingRef.current) {
+ frame = 0;
+ return;
+ }
+ frame = requestAnimationFrame(onFrame);
+ const list = scroller.current;
+ if (list) {
+ const rect = list.getBoundingClientRect();
+ if (at.y < rect.top + EDGE_PX) list.scrollTop -= EDGE_STEP_PX;
+ else if (at.y > rect.bottom - EDGE_PX) {
+ list.scrollTop += EDGE_STEP_PX;
+ }
+ }
+ showTarget(aim(at.x, at.y));
+ };
+ const self = {
+ end: () => {
+ detach();
+ if (started) clear();
+ },
+ };
+ press.current = self;
+
+ // Swallow the release's click, which would load the row it lands on.
+ const swallowClick = () => {
+ const stop = (clicked: MouseEvent) => {
+ clicked.preventDefault();
+ clicked.stopPropagation();
+ };
+ window.addEventListener("click", stop, { capture: true, once: true });
+ window.setTimeout(() => {
+ window.removeEventListener("click", stop, { capture: true });
+ }, 0);
+ };
+
+ function onMove(moved: PointerEvent) {
+ if (moved.pointerId !== pointerId || escaped) return;
+ at.x = moved.clientX;
+ at.y = moved.clientY;
+ if (!started) {
+ if (
+ Math.abs(moved.clientX - startX) < DRAG_THRESHOLD_PX &&
+ Math.abs(moved.clientY - startY) < DRAG_THRESHOLD_PX
+ ) {
+ return;
+ }
+ started = true;
+ scroller.current = scrollerOf(row);
+ document.body.classList.add(DRAGGING_BODY_CLASS);
+ try {
+ document.body.setPointerCapture(pointerId);
+ } catch {
+ // No capture: window listeners still carry the drag inside the window.
+ }
+ draggingRef.current = key;
+ setDraggingKey(key);
+ frame = requestAnimationFrame(onFrame);
+ }
+ moved.preventDefault();
+ showTarget(aim(moved.clientX, moved.clientY));
+ }
+
+ function onUp(released: PointerEvent) {
+ if (released.pointerId !== pointerId) return;
+ detach();
+ if (!started) return;
+ swallowClick();
+ if (escaped) return;
+ const drop = aim(released.clientX, released.clientY);
+ clear();
+ if (drop) optionsRef.current.onDrop(key, drop);
+ }
+
+ function onCancel(aborted: PointerEvent) {
+ if (aborted.pointerId !== pointerId) return;
+ detach();
+ if (started) clear();
+ }
+
+ function onKey(pressed: KeyboardEvent) {
+ if (pressed.key !== "Escape" || escaped) return;
+ if (!started) {
+ detach();
+ return;
+ }
+ // Cancel the drag without closing the selector.
+ pressed.preventDefault();
+ pressed.stopPropagation();
+ // Keep listening so the pending release is still swallowed.
+ escaped = true;
+ clear();
+ }
+
+ window.addEventListener("pointermove", onMove);
+ window.addEventListener("pointerup", onUp);
+ window.addEventListener("pointercancel", onCancel);
+ window.addEventListener("keydown", onKey, true);
+ },
+ }),
+ [aim, clear, showTarget],
+ );
+
+ const lineEdge = useCallback(
+ (key: string): PinnedDropEdge | undefined =>
+ target?.key === key ? target.edge : undefined,
+ [target],
+ );
+
+ return { draggingKey, lineEdge, rowProps };
+}
diff --git a/studio/frontend/tests/connected-model-row-actions.test.ts b/studio/frontend/tests/connected-model-row-actions.test.ts
index ea5bcc4c385..49010fb7548 100644
--- a/studio/frontend/tests/connected-model-row-actions.test.ts
+++ b/studio/frontend/tests/connected-model-row-actions.test.ts
@@ -47,11 +47,11 @@ test("a connected row draws its badges through ModelRow", () => {
// drop there could not be honoured.
assert.match(
pickers,
- /pinnedConnectedRows\.map\(\(model\) =>\s*renderConnectedModelRow\(model, true, true\)/,
+ /pinnedConnectedRows\.map\(\(model\) =>\s*renderPinnedDragRow\(\s*pinnedConnectedDrag,\s*model\.id,\s*renderConnectedModelRow\(model, true\)/,
);
assert.match(
pickers,
- /group\.models\.map\(\(model\) =>\s*renderConnectedModelRow\(model, false, !headed\)/,
+ /group\.models\.map\(\(model\) =>\s*renderConnectedModelRow\(model, !headed\)/,
);
});
@@ -539,8 +539,8 @@ test("live effort edits use the shared runtime action", () => {
test("a row with no heading over it still names its connection", () => {
// Pinned rows and the name-sorted flat list have no provider heading, and two connections can
// serve one model id, so the tooltip carries the connection name those rows have nowhere else.
- assert.match(pickers, /renderConnectedModelRow\(model, true, true\)/);
- assert.match(pickers, /renderConnectedModelRow\(model, false, !headed\)/);
+ assert.match(pickers, /renderConnectedModelRow\(model, true\)/);
+ assert.match(pickers, /renderConnectedModelRow\(model, !headed\)/);
assert.match(pickers, /<span className="block text-ui-10 mt-1">\s*\{model\.providerName\}/);
// No logo in the leading slot: down the pinned group it read as a second glyph column, and a
// row is there to carry its name. So nothing goes in the slot at all now.
diff --git a/studio/frontend/tests/pinned-models-drop-anchor.test.ts b/studio/frontend/tests/pinned-models-drop-anchor.test.ts
new file mode 100644
index 00000000000..7ef491ca09d
--- /dev/null
+++ b/studio/frontend/tests/pinned-models-drop-anchor.test.ts
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import {
+ installLocalStorageFake,
+ registerBundlerResolver,
+} from "./helpers/kit.ts";
+
+registerBundlerResolver();
+installLocalStorageFake();
+
+const { pinDropAnchor, usePinnedModelsStore } = await import(
+ "../src/features/model-picker/components/model-selector/pinned-models.ts"
+);
+
+type Edge = "top" | "bottom";
+
+/** Lands `from` on `edge` of `target` the way the picker's drop does. */
+function drop(pinned: string[], from: string, target: string, edge: Edge) {
+ usePinnedModelsStore.setState({ pinned });
+ const store = usePinnedModelsStore.getState();
+ const anchor = pinDropAnchor(store.pinned, from, target, edge);
+ if (anchor) {
+ store.beginPinnedDrag();
+ store.movePinned(from, anchor);
+ store.endPinnedDrag(true);
+ }
+ return usePinnedModelsStore.getState().pinned;
+}
+
+test("a row lands above or below its target, moving either way", () => {
+ const list = ["a", "b", "c", "d"];
+ assert.deepEqual(drop(list, "a", "c", "top"), ["b", "a", "c", "d"]);
+ assert.deepEqual(drop(list, "a", "c", "bottom"), ["b", "c", "a", "d"]);
+ assert.deepEqual(drop(list, "d", "b", "top"), ["a", "d", "b", "c"]);
+ assert.deepEqual(drop(list, "d", "b", "bottom"), ["a", "b", "d", "c"]);
+ assert.deepEqual(drop(list, "a", "d", "bottom"), ["b", "c", "d", "a"]);
+ assert.deepEqual(drop(list, "d", "a", "top"), ["d", "a", "b", "c"]);
+});
+
+test("a drop into the slot a row already holds is a no-op", () => {
+ const list = ["a", "b", "c"];
+ assert.equal(pinDropAnchor(list, "b", "b", "top"), null);
+ assert.equal(pinDropAnchor(list, "b", "c", "top"), null);
+ assert.equal(pinDropAnchor(list, "b", "a", "bottom"), null);
+ assert.equal(pinDropAnchor(list, "b", "missing", "top"), null);
+ assert.equal(pinDropAnchor(list, "missing", "a", "top"), null);
+});
+
+test("pins that are not drawn keep their place relative to the target", () => {
+ // "h" is pinned but filtered out of view; dropping "c" above "a" still lands it right above "a".
+ assert.deepEqual(drop(["a", "h", "b", "c"], "c", "a", "top"), [
+ "c",
+ "a",
+ "h",
+ "b",
+ ]);
+ assert.deepEqual(drop(["a", "h", "b", "c"], "a", "b", "bottom"), [
+ "h",
+ "b",
+ "a",
+ "c",
+ ]);
+});