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: make sidebar drop cues say where the row actually lands (#11589)

Michael Han22391581b9d7
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsx
index 57b4b6111e4..5ef369ec5a4 100644
--- a/studio/frontend/src/components/app-sidebar.tsx
+++ b/studio/frontend/src/components/app-sidebar.tsx
@@ -236,6 +236,7 @@ import { useIsCoarsePointer } from "@/hooks/use-mobile";
import {
folderRingKey,
sectionRingKey,
+ SIDEBAR_TAIL_ID,
useSidebarDrag,
type SidebarDragItem,
type SidebarDropContext,
@@ -1856,24 +1857,31 @@ export function AppSidebar() {
if (effects.unpinProject && pinnedProjectIdSet.has(effects.unpinProject)) {
toggleProjectPin(effects.unpinProject);
}
- const applyOrders = (before?: Record<string, string[]>) => {
+ // `superseded` once the user has picked a sort since the drop: that is the newer intent, so
+ // the drop's switch to Manual is dropped rather than overwriting it.
+ const applyOrders = (
+ before?: Record<string, string[]>,
+ superseded?: boolean,
+ ) => {
for (const order of effects.orders) {
setManualOrder(
order.scope,
before ? landedOrder(order, before[order.scope]) : order.ids,
);
}
- if (effects.switchSort === "chats" && chatSort !== "manual") {
+ if (superseded) return;
+ if (effects.switchSort === "chats") {
setChatSort("manual");
toast.info(t("shell.organize.switchedToManual"));
}
- if (effects.switchSort === "pinned" && pinnedSort !== "manual") {
+ if (effects.switchSort === "pinned") {
setPinnedSort("manual");
toast.info(t("shell.organize.switchedToManual"));
}
};
const move = effects.moveChat;
if (!move) {
+ // Nothing to wait for, so nothing can come between the drop and this.
applyOrders();
return;
}
@@ -1887,13 +1895,30 @@ export function AppSidebar() {
const moves = chatMovesRef.current;
const previous = moves.get(item.id);
const generation = (previous?.generation ?? 0) + 1;
+ // Watches for the change itself, not the value before against the value after: a sort picked
+ // and picked back while the move is in flight reads as untouched by value, and it is not.
+ // Only the one list this drop would switch, since the two sorts are independent: a pick in
+ // the other is no intent about this one, and standing down for it would leave the slot
+ // written into a list still sorted, which is the drop ignored all over again.
+ const switching = effects.switchSort;
+ let sortPicked = false;
+ const stopWatchingSort = switching
+ ? useSidebarOrganizationStore.subscribe((now, before) => {
+ sortPicked ||=
+ switching === "pinned"
+ ? now.pinnedSort !== before.pinnedSort
+ : now.chatSort !== before.chatSort;
+ })
+ : () => {};
const chain = (previous?.chain ?? Promise.resolve())
.then(() => moveChatToProject(item, move.projectId))
.then((moved) => {
if (!moved || moves.get(item.id)?.generation !== generation) return;
- applyOrders(ordersBefore);
+ // Read before applyOrders, whose own switch would otherwise trip the watch.
+ applyOrders(ordersBefore, sortPicked);
if (unpinAfter) usePinnedChatsStore.getState().unpin(unpinAfter);
- });
+ })
+ .finally(stopWatchingSort);
moves.set(item.id, { generation, chain });
}
@@ -4331,6 +4356,28 @@ export function AppSidebar() {
sort: { value: pinnedSort, set: setPinnedSort },
}),
)}
+ {/* The end of the list, as somewhere to aim. A folder last in Pinned runs its
+ block to the bottom of the section, so every pixel down there is inside it
+ and a chat meant to go after the folder was filed into it instead.
+ Always drawn, never only while a row is carried: a row appearing at drag
+ start shifts every section under it after the pointer was sampled, and the
+ bottom fade measures a height this one would not be counted in.
+ It draws its own line, since the line under the folder's last chat already
+ means "into the folder, last" and the same pixels cannot mean both. */}
+ <SidebarMenuItem
+ aria-hidden
+ className={cn(
+ "relative h-[calc(8px*var(--ui-space-scale,1))]",
+ dropCueClass(PINNED_ORDER_SCOPE, SIDEBAR_TAIL_ID),
+ )}
+ {...dnd.dropZoneProps({
+ section: "pinned",
+ blockEnd: {
+ scope: PINNED_ORDER_SCOPE,
+ id: SIDEBAR_TAIL_ID,
+ },
+ })}
+ />
</SidebarMenu>
</SidebarGroupContent>
</CollapsibleContent>
@@ -4414,6 +4461,17 @@ export function AppSidebar() {
section: "projects",
}),
)}
+ {/* Every project is pinned, so the section is drawn with nothing in it. The
+ line gives the body a height: without one it collapses to zero and the
+ hit test walks straight past it, so a pinned folder dragged back has
+ nowhere to land and nothing lights up. */}
+ {visibleProjectRecords.length === 0 && (
+ <SidebarMenuItem>
+ <p className="flex h-[calc(30px*var(--ui-space-scale,1))] items-center pl-3 pr-4 text-ui-13 leading-ui-18 tracking-nav text-nav-fg-muted">
+ {t("shell.navigation.allProjectsPinned")}
+ </p>
+ </SidebarMenuItem>
+ )}
{/* Long project lists stay one row deep until asked. */}
{sidebarProjectRecords.length > SIDEBAR_PROJECT_LIMIT && (
<SidebarMenuItem>
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 4da87c2912b..b960e6c21b6 100644
--- a/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts
+++ b/studio/frontend/src/features/chat/hooks/use-sidebar-drag.ts
@@ -190,16 +190,14 @@ export function useSidebarDrag(options: UseSidebarDragOptions): SidebarDragApi {
[],
);
- /** One step of the edge scroll, true when the list actually moved. Driven by the frame loop,
- * not by pointermove: a pointer resting on the edge sends no moves and would stall. */
- const edgeScroll = useCallback((y: number): boolean => {
+ /** One step of the edge scroll. Driven by the frame loop, not by pointermove: a pointer resting
+ * on the edge sends no moves and would stall. */
+ const edgeScroll = useCallback((y: number) => {
const list = scroller.current;
- if (!list) return false;
+ if (!list) return;
const rect = list.getBoundingClientRect();
- const before = list.scrollTop;
if (y < rect.top + EDGE_PX) list.scrollTop -= EDGE_STEP_PX;
else if (y > rect.bottom - EDGE_PX) list.scrollTop += EDGE_STEP_PX;
- return list.scrollTop !== before;
}, []);
const track = useCallback(
@@ -270,8 +268,10 @@ export function useSidebarDrag(options: UseSidebarDragOptions): SidebarDragApi {
document.body.releasePointerCapture(pointerId);
}
};
- // Scrolling moves the rows, not the pointer, so the frame that scrolls re-aims too or
- // the cue would sit on whichever row has slid out from under the pointer.
+ // The rows move under the pointer, not the other way about: the list edge-scrolls, a
+ // folder springs open under a pointer that by definition is resting. So every frame
+ // re-aims, not only the ones that scroll, or the cue would describe the layout as it was
+ // when the pointer last moved while the release hit-tests the layout as it is.
const onFrame = () => {
// Self-terminating, so an unmount mid-drag cannot leave the loop running.
if (!sidebarDragSource()) {
@@ -279,7 +279,8 @@ export function useSidebarDrag(options: UseSidebarDragOptions): SidebarDragApi {
return;
}
frame = requestAnimationFrame(onFrame);
- if (edgeScroll(at.y)) track(at.x, at.y);
+ edgeScroll(at.y);
+ track(at.x, at.y);
};
// Abandons this gesture whole, for a drop that never came: the same as a cancel.
const self = {
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index 41f7c71d611..8c6d1631ee3 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -116,6 +116,7 @@ export {
planSidebarDrop,
rowKey,
sectionRingKey,
+ SIDEBAR_TAIL_ID,
STAY,
type DropEdge,
type SidebarDragItem,
diff --git a/studio/frontend/src/features/chat/lib/sidebar-drag.ts b/studio/frontend/src/features/chat/lib/sidebar-drag.ts
index abbd0bce895..e663d6f4339 100644
Binary files a/studio/frontend/src/features/chat/lib/sidebar-drag.ts and b/studio/frontend/src/features/chat/lib/sidebar-drag.ts differ
diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.ts
index 9d447b4539f..515ca526349 100644
--- a/studio/frontend/src/i18n/locales/ar.ts
+++ b/studio/frontend/src/i18n/locales/ar.ts
@@ -164,6 +164,8 @@ export const ar = {
noChatsYet: "لا توجد محادثات بعد",
// Shown under an empty project folder in the sidebar.
noChats: "لا توجد محادثات",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "كل المشاريع مثبتة",
showMore: "عرض المزيد",
showLess: "عرض أقل",
settings: "الإعدادات",
diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.ts
index 13c35e9382e..a3d34a43b58 100644
--- a/studio/frontend/src/i18n/locales/de.ts
+++ b/studio/frontend/src/i18n/locales/de.ts
@@ -167,6 +167,8 @@ export const de = {
noChatsYet: "Noch keine Chats",
// Shown under an empty project folder in the sidebar.
noChats: "Keine Chats",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "Alle Projekte angepinnt",
showMore: "Mehr anzeigen",
showLess: "Weniger anzeigen",
settings: "Einstellungen",
diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.ts
index 80c8639701c..52e451305e6 100644
--- a/studio/frontend/src/i18n/locales/en.ts
+++ b/studio/frontend/src/i18n/locales/en.ts
@@ -167,6 +167,8 @@ export const en = {
noChatsYet: "No chats yet",
// Shown under an empty project folder in the sidebar.
noChats: "No chats",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "All projects pinned",
showMore: "Show more",
showLess: "Show less",
settings: "Settings",
diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.ts
index b7d50ce5590..bc2eda16f25 100644
--- a/studio/frontend/src/i18n/locales/es.ts
+++ b/studio/frontend/src/i18n/locales/es.ts
@@ -166,6 +166,8 @@ export const es = {
noChatsYet: "Aún no hay chats",
// Shown under an empty project folder in the sidebar.
noChats: "Sin chats",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "Todos los proyectos fijados",
showMore: "Mostrar más",
showLess: "Mostrar menos",
settings: "Configuración",
diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.ts
index afcce783380..5e4b67d566b 100644
--- a/studio/frontend/src/i18n/locales/fr.ts
+++ b/studio/frontend/src/i18n/locales/fr.ts
@@ -167,6 +167,8 @@ export const fr = {
noChatsYet: "Aucune discussion pour le moment",
// Shown under an empty project folder in the sidebar.
noChats: "Aucune discussion",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "Tous les projets sont epingles",
showMore: "Afficher plus",
showLess: "Afficher moins",
settings: "Paramètres",
diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.ts
index 6c040d96786..18f20aefcf4 100644
--- a/studio/frontend/src/i18n/locales/hi.ts
+++ b/studio/frontend/src/i18n/locales/hi.ts
@@ -167,6 +167,8 @@ export const hi = {
noChatsYet: "अभी तक कोई चैट नहीं",
// Shown under an empty project folder in the sidebar.
noChats: "कोई चैट नहीं",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "सभी प्रोजेक्ट पिन किए गए",
showMore: "और दिखाएं",
showLess: "कम दिखाएं",
settings: "सेटिंग्स",
diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.ts
index c2dc3532ba8..b91f95815cc 100644
--- a/studio/frontend/src/i18n/locales/it.ts
+++ b/studio/frontend/src/i18n/locales/it.ts
@@ -131,6 +131,8 @@ export const it = {
noChatsYet: "Ancora nessuna chat",
// Shown under an empty project folder in the sidebar.
noChats: "Nessuna chat",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "Tutti i progetti fissati",
showMore: "Mostra altro",
showLess: "Mostra meno",
settings: "Impostazioni",
diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.ts
index c334ef4206b..c0dd43da4e7 100644
--- a/studio/frontend/src/i18n/locales/ja.ts
+++ b/studio/frontend/src/i18n/locales/ja.ts
@@ -166,6 +166,8 @@ export const ja = {
noChatsYet: "チャットがまだありません",
// Shown under an empty project folder in the sidebar.
noChats: "チャットなし",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "すべてのプロジェクトをピン留め済み",
showMore: "もっと見る",
showLess: "表示を減らす",
settings: "設定",
diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.ts
index 57527b0fc5d..12768258cdb 100644
--- a/studio/frontend/src/i18n/locales/ko.ts
+++ b/studio/frontend/src/i18n/locales/ko.ts
@@ -164,6 +164,8 @@ export const ko = {
noChatsYet: "아직 채팅이 없습니다",
// Shown under an empty project folder in the sidebar.
noChats: "채팅 없음",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "모든 프로젝트가 고정됨",
showMore: "더 보기",
showLess: "간략히 보기",
settings: "설정",
diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.ts
index c9aa9a8a2ee..7a6ee2322d6 100644
--- a/studio/frontend/src/i18n/locales/pt-br.ts
+++ b/studio/frontend/src/i18n/locales/pt-br.ts
@@ -166,6 +166,8 @@ export const ptBR = {
noChatsYet: "Nenhum chat ainda",
// Shown under an empty project folder in the sidebar.
noChats: "Nenhum chat",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "Todos os projetos fixados",
showMore: "Mostrar mais",
showLess: "Mostrar menos",
settings: "Configurações",
diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.ts
index ac4ea4b4cc8..ac99b1963f0 100644
--- a/studio/frontend/src/i18n/locales/ru.ts
+++ b/studio/frontend/src/i18n/locales/ru.ts
@@ -166,6 +166,8 @@ export const ru = {
noChatsYet: "Пока нет чатов",
// Shown under an empty project folder in the sidebar.
noChats: "Нет чатов",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "Все проекты закреплены",
showMore: "Показать больше",
showLess: "Показать меньше",
settings: "Настройки",
diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.ts
index 48d55aa4709..648c0669f91 100644
--- a/studio/frontend/src/i18n/locales/zh-CN.ts
+++ b/studio/frontend/src/i18n/locales/zh-CN.ts
@@ -162,6 +162,8 @@ export const zhCN = {
noChatsYet: "暂无对话",
// Shown under an empty project folder in the sidebar.
noChats: "无对话",
+ // Shown in the Projects section when every project is pinned, so it has no rows.
+ allProjectsPinned: "所有项目均已置顶",
showMore: "显示更多",
showLess: "显示更少",
settings: "设置",
diff --git a/studio/frontend/tests/sidebar-row-drag.test.ts b/studio/frontend/tests/sidebar-row-drag.test.ts
index 50cff29d8b6..3533d153278 100644
--- a/studio/frontend/tests/sidebar-row-drag.test.ts
+++ b/studio/frontend/tests/sidebar-row-drag.test.ts
@@ -14,6 +14,7 @@ import {
planSidebarDrop,
rowKey,
sectionRingKey,
+ SIDEBAR_TAIL_ID,
STAY,
type SidebarDragItem,
type SidebarDropOutcome,
@@ -231,7 +232,19 @@ test("a chat dropped on a folder, its chats or its empty line is filed there", (
planSidebarDrop(drag, zone, zone.edge ?? "top", context()),
);
assert.deepEqual(plan.action, { kind: "move", projectId: zone.folderId });
- assert.deepEqual(plan.cue, { ring: folderRingKey(zone.folderId!) });
+ // A row to land against gives a slot, whatever the list is sorted by. Only a folder row or
+ // an empty line, with nothing to aim at, lights the folder whole.
+ assert.deepEqual(
+ plan.cue,
+ zone.row?.kind === "chat"
+ ? {
+ line: {
+ rowKey: rowKey(zone.row.scope, zone.row.id),
+ edge: zone.edge ?? "top",
+ },
+ }
+ : { ring: folderRingKey(zone.folderId!) },
+ );
assert.deepEqual(plan.effects.moveChat, {
chatId: "r1",
projectId: zone.folderId,
@@ -287,8 +300,33 @@ test("a chat dropped on Recents leaves its folder and its pin", () => {
),
);
assert.deepEqual(unfiled.action, { kind: "move", projectId: null });
- assert.deepEqual(unfiled.cue, { ring: sectionRingKey("recents") });
assert.deepEqual(unfiled.effects.moveChat, { chatId: "c3", projectId: null });
+ // The section's own space lands last, the slot Pinned already gives it, so the line says where
+ // the chat is going instead of the whole section saying only that it is going in there.
+ assert.deepEqual(unfiled.cue, {
+ line: { rowKey: rowKey(RECENTS_ORDER_SCOPE, "r2"), edge: "bottom" },
+ });
+ assert.deepEqual(unfiled.effects.orders, [
+ {
+ scope: RECENTS_ORDER_SCOPE,
+ ids: ["r1", "r2", "c3"],
+ place: { id: "c3", targetId: "r2", edge: "bottom" },
+ },
+ ]);
+ // And the slot sticks: a sorted list would put the chat back where the sort wants it.
+ assert.equal(unfiled.effects.switchSort, "chats");
+ // Empty Recents has no row to land against, so the section is the target.
+ assert.deepEqual(
+ plannedDrop(
+ planSidebarDrop(
+ chat("c3", "projects", projectOrderScope("home"), "home"),
+ { section: "recents" },
+ "top",
+ context({ orders: { ...context().orders, recents: [] } }),
+ ),
+ ).cue,
+ { ring: sectionRingKey("recents") },
+ );
// Out of Pinned: the pin goes, and so does the folder that would keep it out of Recents.
const unpinned = plannedDrop(
planSidebarDrop(
@@ -611,6 +649,36 @@ test("a folder dragged into Pinned is pinned where it lands, and back out is unp
assert.deepEqual(unpinOnHeader.cue, { ring: sectionRingKey("projects") });
});
+// Pinning the last project leaves the section drawn but empty, and that is exactly when a folder
+// is dragged back into it.
+test("an empty Projects section still shows where a folder would land", () => {
+ const ctx = context({
+ pinnedProjectIds: new Set(["work", "home", "misc"]),
+ orders: { ...context().orders, projects: [] },
+ });
+ const onBody = plannedDrop(
+ planSidebarDrop(
+ folder("work", "pinned", PINNED_ORDER_SCOPE),
+ { section: "projects" },
+ "bottom",
+ ctx,
+ ),
+ );
+ // No folder to land against, so the whole section is the target.
+ assert.deepEqual(onBody.action, { kind: "unpin" });
+ assert.deepEqual(onBody.cue, { ring: sectionRingKey("projects") });
+ assert.deepEqual(onBody.effects.orders, [
+ { scope: PROJECT_ORDER_SCOPE, ids: ["work"] },
+ ]);
+ // The ring is painted on the section body, which is only there to be painted and hit if the
+ // empty section draws a row. A zero-height box is skipped by elementsFromPoint.
+ assert.match(
+ APP_SIDEBAR,
+ /\{visibleProjectRecords\.length === 0 && \(\n\s*<SidebarMenuItem>\n\s*<p className="[^"]*text-nav-fg-muted">\n\s*\{t\("shell\.navigation\.allProjectsPinned"\)\}/,
+ );
+ assert.match(EN, /allProjectsPinned: "All projects pinned",/);
+});
+
// The gap between a header and its first row is where "above the first row" is aimed, so the
// header stands for that edge for a drag of the same kind, and for the bare section otherwise.
test("a section header stands for the top of its first row", () => {
@@ -807,7 +875,12 @@ test("a chat dropped again before its move lands keeps only the latest drop", ()
);
assert.match(
APP_SIDEBAR,
- /const generation = \(previous\?\.generation \?\? 0\) \+ 1;\n\s*const chain = \(previous\?\.chain \?\? Promise\.resolve\(\)\)\n\s*\.then\(\(\) => moveChatToProject\(item, move\.projectId\)\)/,
+ /const generation = \(previous\?\.generation \?\? 0\) \+ 1;/,
+ );
+ // This drop's work is queued behind the one before it, never alongside.
+ assert.match(
+ APP_SIDEBAR,
+ /const chain = \(previous\?\.chain \?\? Promise\.resolve\(\)\)\n\s*\.then\(\(\) => moveChatToProject\(item, move\.projectId\)\)/,
);
assert.match(APP_SIDEBAR, /moves\.set\(item\.id, \{ generation, chain \}\);/);
});
@@ -931,6 +1004,12 @@ test("a closed folder or section opens under a resting pointer", () => {
/if \(!closed\) \{\n\s*if \(spring\.current\?\.key !== springKey\) cancelSpring\(\);\n\s*return;\n\s*\}/,
);
assert.match(HOOK, /zoneOptions\?\.closed \? \{ zone, closed: true \} : \{ zone \}/);
+ // The timer is keyed and left alone while the pointer stays on the same zone. track runs every
+ // frame now, so re-arming on each one would reset the delay forever and nothing would open.
+ assert.match(
+ HOOK,
+ /if \(spring\.current\?\.key === springKey\) return;\n\s*cancelSpring\(\);\n\s*spring\.current = \{/,
+ );
});
// A chat dropped into a folder or Recents is moved, and the move can fail. Its slot in the new
@@ -943,11 +1022,11 @@ test("a drop that moves writes its slot and takes the pin off after the move", (
);
assert.match(
APP_SIDEBAR,
- /const move = effects\.moveChat;\n\s*if \(!move\) \{\n\s*applyOrders\(\);\n\s*return;\n\s*\}/,
+ /const move = effects\.moveChat;\n\s*if \(!move\) \{\n(?:\s*\/\/[^\n]*\n)*\s*applyOrders\(\);\n\s*return;\n\s*\}/,
);
assert.match(
APP_SIDEBAR,
- /\.then\(\(\) => moveChatToProject\(item, move\.projectId\)\)\n\s*\.then\(\(moved\) => \{\n\s*if \(!moved \|\| moves\.get\(item\.id\)\?\.generation !== generation\) return;\n\s*applyOrders\(ordersBefore\);\n\s*if \(unpinAfter\) usePinnedChatsStore\.getState\(\)\.unpin\(unpinAfter\);/,
+ /\.then\(\(\) => moveChatToProject\(item, move\.projectId\)\)\n\s*\.then\(\(moved\) => \{\n\s*if \(!moved \|\| moves\.get\(item\.id\)\?\.generation !== generation\) return;\n(?:\s*\/\/[^\n]*\n)*\s*applyOrders\(ordersBefore, sortPicked\);\n\s*if \(unpinAfter\) usePinnedChatsStore\.getState\(\)\.unpin\(unpinAfter\);/,
);
// And nothing else in commitDrop writes an order on its own.
const commit = APP_SIDEBAR.slice(
@@ -975,12 +1054,121 @@ test("a drop that moves writes its slot and takes the pin off after the move", (
);
});
+// applyOrders runs after the move on that path, and it is a closure: a sort read from the render
+// it was made in is the drop-time one for good, so a sort the user picked while the move was in
+// flight would be overwritten with Manual.
+test("a sort picked while a move is in flight is not overwritten", () => {
+ const commit = APP_SIDEBAR.slice(
+ APP_SIDEBAR.indexOf("function commitDrop("),
+ APP_SIDEBAR.indexOf("function dropCueClass("),
+ );
+ // The change itself is watched. A value read at the drop and again at the end cannot tell a
+ // sort picked and picked back from one never touched, and that is a newer intent either way.
+ // And only the list this drop switches: the other sort governs another list, so standing down
+ // for it would leave the slot written into a list still sorted, undoing the drop.
+ assert.match(
+ commit,
+ /const stopWatchingSort = switching\n\s*\? useSidebarOrganizationStore\.subscribe\(\(now, before\) => \{\n\s*sortPicked \|\|=\n\s*switching === "pinned"\n\s*\? now\.pinnedSort !== before\.pinnedSort\n\s*: now\.chatSort !== before\.chatSort;\n\s*\}\)\n\s*: \(\) => \{\};/,
+ );
+ assert.match(commit, /const switching = effects\.switchSort;/);
+ // Only the path that waits. Nothing can come between a drop and a switch applied in the turn.
+ assert.match(
+ commit,
+ /if \(!move\) \{\n(?:\s*\/\/[^\n]*\n)*\s*applyOrders\(\);\n\s*return;\n\s*\}/,
+ );
+ // Read before applyOrders, whose own setChatSort would otherwise trip the watch it reads.
+ assert.match(commit, /applyOrders\(ordersBefore, sortPicked\);/);
+ // Released on every ending, including a move that failed or was superseded.
+ assert.match(commit, /\.finally\(stopWatchingSort\);/);
+ // And the switch no longer second-guesses the plan by re-testing the sort's value.
+ assert.ok(
+ !/chatSort !== "manual"|pinnedSort !== "manual"|=== sortAtDrop\./.test(commit),
+ "the switch still tests a sort value",
+ );
+});
+
+// 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("a chat can be dropped after a folder that ends the Pinned list", () => {
+ const workScope = projectOrderScope("work");
+ const ctx = context({
+ pinnedChatIds: new Set(),
+ orders: {
+ ...context().orders,
+ pinned: ["work"],
+ projectChats: () => ["w1", "w2"],
+ },
+ });
+ const drag = chat("r1", "recents", RECENTS_ORDER_SCOPE, null);
+ // As the folder's chat rows are drawn: the block's last row names itself as its end.
+ const lastInBlock: SidebarDropZone = {
+ ...chatRow("pinned", workScope, "w2", "work", { index: 1, count: 2 }),
+ blockEnd: { scope: workScope, id: "w2" },
+ };
+ // The lowest row of the block still means "into the folder, last", which is the other fix.
+ const intoFolder = plannedDrop(
+ planSidebarDrop(drag, lastInBlock, "bottom", ctx),
+ );
+ assert.deepEqual(intoFolder.action, { kind: "move", projectId: "work" });
+ // The section's tail is a row of its own, so "after the folder" has somewhere to aim.
+ const afterFolder = plannedDrop(
+ planSidebarDrop(
+ drag,
+ {
+ section: "pinned",
+ blockEnd: { scope: PINNED_ORDER_SCOPE, id: SIDEBAR_TAIL_ID },
+ },
+ "bottom",
+ ctx,
+ ),
+ );
+ assert.deepEqual(afterFolder.action, { kind: "pin" });
+ assert.deepEqual(afterFolder.effects.orders, [
+ { scope: PINNED_ORDER_SCOPE, ids: ["work", "r1"] },
+ ]);
+ // Its own line, not the one under the folder's last chat: same pixels would be two drops.
+ assert.deepEqual(afterFolder.cue, {
+ line: { rowKey: rowKey(PINNED_ORDER_SCOPE, SIDEBAR_TAIL_ID), edge: "bottom" },
+ });
+ assert.notDeepEqual(afterFolder.cue, intoFolder.cue);
+ // Part of the layout, not summoned by the drag: a row mounting at drag start shifts every
+ // section below it after the pointer was sampled, and the cue and the drop then disagree.
+ const pinnedMenu = APP_SIDEBAR.slice(
+ APP_SIDEBAR.indexOf('{/* Pinned: folders and chats in one list'),
+ APP_SIDEBAR.indexOf("{/* One folder per unpinned project."),
+ );
+ 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\(PINNED_ORDER_SCOPE, SIDEBAR_TAIL_ID\),/,
+ );
+ assert.ok(
+ !/draggingRow && /.test(pinnedMenu),
+ "the tail is conditional on a drag again",
+ );
+ // A folder over another folder's block still lands below that block, as it always did.
+ assert.deepEqual(
+ plannedDrop(
+ planSidebarDrop(
+ folder("home", "projects", PROJECT_ORDER_SCOPE),
+ lastInBlock,
+ "bottom",
+ ctx,
+ ),
+ ).cue,
+ { line: { rowKey: rowKey(workScope, "w2"), edge: "bottom" } },
+ );
+});
+
// A pointer resting on the edge of a long list sends no more moves, so scrolling driven off
-// pointermove alone took one step and stalled. The frame loop keeps it going, and re-aims: the
-// rows slide under a pointer that has not moved, so the cue would otherwise stay on the row that
-// left.
+// pointermove alone took one step and stalled. The frame loop keeps it going, and re-aims every
+// frame: rows slide under a pointer that has not moved when the list scrolls, when a folder
+// springs open under it, and when the sidebar re-renders, and only the frame loop is there to
+// see it. The release hit-tests the layout as it is, so the cue has to as well.
test("the edge keeps scrolling while the pointer rests on it", () => {
- assert.match(HOOK, /const onFrame = \(\) => \{[^]*?frame = requestAnimationFrame\(onFrame\);\n\s*if \(edgeScroll\(at\.y\)\) track\(at\.x, at\.y\);/);
+ assert.match(HOOK, /const onFrame = \(\) => \{[^]*?frame = requestAnimationFrame\(onFrame\);\n\s*edgeScroll\(at\.y\);\n\s*track\(at\.x, at\.y\);/);
+ // Unconditionally: a re-aim only on the frames that scrolled leaves every other cause stale.
+ assert.ok(!/if \(edgeScroll\(/.test(HOOK));
// Started with the drag and cancelled with it, and it stops itself if the drag is gone.
assert.match(HOOK, /setDrag\(item\);\n\s*frame = requestAnimationFrame\(onFrame\);/);
assert.match(HOOK, /if \(frame\) cancelAnimationFrame\(frame\);/);
@@ -1032,3 +1220,64 @@ test("escape keeps the click guard until the button is released", () => {
// And a cancelled drag does not come back to life on the next move.
assert.match(HOOK, /if \(moved\.pointerId !== pointerId \|\| escaped\) return;/);
});
+
+// Two ways the bottom of a pinned project was unreachable.
+test("a chat can be dropped at the bottom of a pinned project", () => {
+ const workScope = projectOrderScope("work");
+ const lastRow = chatRow("pinned", workScope, "p2", "work", {
+ index: 1,
+ count: 2,
+ });
+ // The default chat sort is Priority, and a chat arriving from another list used to lose its
+ // slot to it: the folder lit whole and the chat landed wherever the sort put it. It keeps the
+ // slot now and the list switches to Manual, the same as a reorder within one.
+ const arriving = plannedDrop(
+ planSidebarDrop(
+ chat("r1", "recents", RECENTS_ORDER_SCOPE, null),
+ lastRow,
+ "bottom",
+ context({ orders: { ...context().orders, projectChats: () => ["p1", "p2"] } }),
+ ),
+ );
+ assert.deepEqual(arriving.cue, {
+ line: { rowKey: rowKey(workScope, "p2"), edge: "bottom" },
+ });
+ assert.equal(arriving.effects.switchSort, "chats");
+ assert.deepEqual(arriving.effects.orders[0]?.ids, ["p1", "p2", "r1"]);
+
+ // A folder of more than PROJECT_CHAT_LIMIT chats draws Show more directly under its last
+ // visible one, and that row is a drop zone with no row of its own. A chat already in the
+ // folder answered nothing there, so there was no way down past the last chat.
+ const tail = plannedDrop(
+ planSidebarDrop(
+ chat("p1", "pinned", workScope, "work"),
+ {
+ section: "pinned",
+ folderId: "work",
+ blockEnd: { scope: workScope, id: "p2" },
+ },
+ "bottom",
+ context({
+ chatSort: "manual",
+ orders: { ...context().orders, projectChats: () => ["p1", "p2", "p3"] },
+ }),
+ ),
+ "the folder's block tail answered nothing",
+ );
+ assert.deepEqual(tail.action, { kind: "reorder" });
+ assert.deepEqual(tail.cue, {
+ line: { rowKey: rowKey(workScope, "p2"), edge: "bottom" },
+ });
+ assert.deepEqual(tail.effects.orders[0]?.ids, ["p2", "p1", "p3"]);
+
+ // The folder's own row is its head, not its tail: the chat is already there.
+ assert.equal(
+ planSidebarDrop(
+ chat("p1", "pinned", workScope, "work"),
+ folderRow("pinned", PINNED_ORDER_SCOPE, "work"),
+ "bottom",
+ context({ chatSort: "manual" }),
+ ),
+ STAY,
+ );
+});