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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: select all and shift-click ranges in the Library (#13250)
Padiasb1f4fdb505df
diff --git a/studio/frontend/src/features/library/components/card-selection.ts b/studio/frontend/src/features/library/components/card-selection.tsindex aae8b3f5e66..27eb97d4aea 100644--- a/studio/frontend/src/features/library/components/card-selection.ts+++ b/studio/frontend/src/features/library/components/card-selection.ts@@ -5,5 +5,6 @@ import { createContext } from "react";export const CardSelectionContext = createContext<{selection: ReadonlySet<string>;- toggle: (key: string) => void;+ /** `range` (a shift click) takes every entry between the last click and this one. */+ toggle: (key: string, range?: boolean) => void;} | null>(null);diff --git a/studio/frontend/src/features/library/components/library-cards.tsx b/studio/frontend/src/features/library/components/library-cards.tsxindex a338f93dd19..23414bb6d54 100644--- a/studio/frontend/src/features/library/components/library-cards.tsx+++ b/studio/frontend/src/features/library/components/library-cards.tsx@@ -147,7 +147,9 @@ function CardFrame({type="button"aria-label={label}aria-pressed={select && selecting ? selected : undefined}- onClick={select && selecting ? () => select.toggle(selectKey) : onOpen}+ onClick={+ select && selecting ? (event) => select.toggle(selectKey, event.shiftKey) : onOpen+ }className={cn("block w-full overflow-hidden rounded-xl text-left outline-none transition focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",selected && "ring-2 ring-foreground",@@ -159,7 +161,11 @@ function CardFrame({{select && (<Checkboxchecked={selected}- onCheckedChange={() => select.toggle(selectKey)}+ // onClick to read shift.+ onClick={(event) => {+ event.preventDefault();+ select.toggle(selectKey, event.shiftKey);+ }}aria-label={t("library.selectItem", { name: label })}className={cn(OVERLAY_CONTROL,@@ -275,10 +281,14 @@ function FolderCard({}) {const t = useT();const actions = useLibraryActions();+ const select = useContext(CardSelectionContext);+ const selectKey = `folder:${folder.id}`;+ // While selecting, the caption selects like the card above it rather than opening the folder.+ const selecting = select && select.selection.size > 0;return (<div><CardFrame- selectKey={`folder:${folder.id}`}+ selectKey={selectKey}label={folder.name}onOpen={() => actions.openFolder(folder.id)}menu={<LibraryActionsMenu target={{ kind: "folder", folder }} variant="overlay" />}@@ -290,7 +300,9 @@ function FolderCard({</CardFrame><buttontype="button"- onClick={() => actions.openFolder(folder.id)}+ onClick={(event) =>+ selecting ? select.toggle(selectKey, event.shiftKey) : actions.openFolder(folder.id)+ }className="mt-2 block w-full px-1 text-left"><p className="truncate font-medium text-ui-14 text-foreground">{folder.name}</p>diff --git a/studio/frontend/src/features/library/components/library-list.tsx b/studio/frontend/src/features/library/components/library-list.tsxindex b510a01d7a5..e89cb07e79b 100644--- a/studio/frontend/src/features/library/components/library-list.tsx+++ b/studio/frontend/src/features/library/components/library-list.tsx@@ -75,20 +75,25 @@ function GutterCheckbox({checked,visible,group,- onCheckedChange,+ onToggle,label,}: {checked: boolean;visible: boolean;group: "row" | "head";- onCheckedChange: () => void;+ /** `range` is a shift click. */+ onToggle: (range: boolean) => void;label: string;}) {return (<div className="absolute right-full top-1/2 mr-3 flex -translate-y-1/2"><Checkboxchecked={checked}- onCheckedChange={onCheckedChange}+ // onClick to read shift.+ onClick={(event) => {+ event.preventDefault();+ onToggle(event.shiftKey);+ }}aria-label={label}className={cn("rounded-full border-neutral-300 opacity-0 transition-opacity focus-visible:opacity-100 dark:border-input",@@ -106,7 +111,7 @@ function Row({target,selected,selecting,- onSelectedChange,+ onToggle,onOpen,tile,name,@@ -118,7 +123,7 @@ function Row({target: LibraryTarget;selected: boolean;selecting: boolean;- onSelectedChange: (selected: boolean) => void;+ onToggle: (range: boolean) => void;onOpen: () => void;tile: ReactNode;name: ReactNode;@@ -141,14 +146,16 @@ function Row({checked={selected}visible={selecting}group="row"- onCheckedChange={() => onSelectedChange(!selected)}+ onToggle={onToggle}label={t("library.selectItem", {name: target.kind === "item" ? target.item.name : target.folder.name,})}/>+ {/* While selecting, a click selects, as a card's does. */}<buttontype="button"- onClick={onOpen}+ aria-pressed={selecting ? selected : undefined}+ onClick={(event) => (selecting ? onToggle(event.shiftKey) : onOpen())}className="flex min-w-0 flex-1 items-center gap-4 rounded-lg py-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring">{tile}@@ -177,6 +184,7 @@ export function LibraryList({counts,selection,onSelectionChange,+ onToggle,sort,onSortChange,activity,@@ -188,6 +196,8 @@ export function LibraryList({counts: Map<string, number>;selection: Set<string>;onSelectionChange: (next: Set<string>) => void;+ /** Select or deselect one row; `range` (a shift click) takes every row since the last click. */+ onToggle: (key: string, range: boolean) => void;sort: LibrarySortState;onSortChange: (key: LibrarySortKey) => void;activity: boolean;@@ -204,13 +214,6 @@ export function LibraryList({const allSelected = targets.length > 0 && targets.every((t) => selection.has(targetKey(t)));const selecting = selection.size > 0;- const setSelected = (target: LibraryTarget, selected: boolean) => {- const next = new Set(selection);- if (selected) next.add(targetKey(target));- else next.delete(targetKey(target));- onSelectionChange(next);- };-return (<div>{/* The padding sits outside the row, so the checkbox centers on the column titles. */}@@ -226,7 +229,7 @@ export function LibraryList({checked={allSelected}visible={selecting}group="head"- onCheckedChange={() =>+ onToggle={() =>onSelectionChange(allSelected ? new Set() : new Set(targets.map(targetKey)))}label={t("library.list.selectAll")}@@ -255,7 +258,7 @@ export function LibraryList({target={{ kind: "folder", folder }}selected={selection.has(`folder:${folder.id}`)}selecting={selecting}- onSelectedChange={(selected) => setSelected({ kind: "folder", folder }, selected)}+ onToggle={(range) => onToggle(`folder:${folder.id}`, range)}onOpen={() => actions.openFolder(folder.id)}tile={<div className="flex size-9 shrink-0 items-center justify-center rounded-[10px] border border-border/60">@@ -280,7 +283,7 @@ export function LibraryList({target={{ kind: "item", item }}selected={selection.has(`item:${item.id}`)}selecting={selecting}- onSelectedChange={(selected) => setSelected({ kind: "item", item }, selected)}+ onToggle={(range) => onToggle(`item:${item.id}`, range)}onOpen={() => actions.openItem(item)}tile={<ItemTile item={item} />}name={diff --git a/studio/frontend/src/features/library/library-page.tsx b/studio/frontend/src/features/library/library-page.tsxindex 68db37be546..96713da2a30 100644--- a/studio/frontend/src/features/library/library-page.tsx+++ b/studio/frontend/src/features/library/library-page.tsx@@ -18,7 +18,8 @@ import {useNativeFileDrop,} from "@/features/native-intents";import { getAuthSessionEpoch } from "@/features/auth";-import { useSettingsDialogStore } from "@/features/settings";+import { rangeBetween } from "@/features/chat";+import { isMacPlatform, useSettingsDialogStore } from "@/features/settings";import { type TranslationKey, useT } from "@/i18n";import { cn } from "@/lib/utils";import { toast } from "@/lib/toast";@@ -227,7 +228,15 @@ function LibraryView({ search }: { search: LibrarySearch }) {const [chosenFilters, setFilters] = useState<LibraryFilters>(() =>search.filter === "files" ? { ...EMPTY_FILTERS, types: new Set(FILE_TYPES) } : EMPTY_FILTERS,);- const [selection, setSelection] = useState<Set<string>>(new Set());+ const [selection, setSelectionState] = useState<Set<string>>(new Set());+ // The entry last clicked, which a shift click ranges from. A key rather than an index: the+ // listing can re-sort between clicks.+ const selectionAnchor = useRef<string | null>(null);+ // Select all and clearing drop the anchor, so a shift click never reaches back past them.+ const setSelection = useCallback((next: Set<string>) => {+ selectionAnchor.current = null;+ setSelectionState(next);+ }, []);const [nameDialog, setNameDialog] = useState<NameDialogState | null>(null);const [pendingDelete, setPendingDelete] = useState<LibraryTarget[] | null>(null);const fileInput = useRef<HTMLInputElement>(null);@@ -366,19 +375,28 @@ function LibraryView({ search }: { search: LibrarySearch }) {.sort(compareBySort(sort.key === "size" ? { key: "name", desc: false } : sort));}, [folders, folderId, tab, needle, filters, sort]);- // A search, filter or Content setting that hides a selected entry deselects it, so bulk actions- // only ever act on what is on screen and clearing the filter never brings a selection back.- const visibleKeys = useMemo(- () =>- new Set([- ...visibleFolders.map((folder) => `folder:${folder.id}`),- ...visibleItems.map((item) => `item:${item.id}`),- ]),+ // Folders then items, the order both views show them in: grid's masonry deals cards across+ // columns row by row, so this is also left to right, top to bottom there.+ const orderedKeys = useMemo(+ () => [+ ...visibleFolders.map((folder) => `folder:${folder.id}`),+ ...visibleItems.map((item) => `item:${item.id}`),+ ],[visibleFolders, visibleItems],);+ // A search, filter or Content setting that hides a selected entry deselects it, so bulk actions+ // only ever act on what is on screen and clearing the filter never brings a selection back.+ const visibleKeys = useMemo(() => new Set(orderedKeys), [orderedKeys]);if ([...selection].some((key) => !visibleKeys.has(key))) {- setSelection(new Set([...selection].filter((key) => visibleKeys.has(key))));+ setSelectionState(new Set([...selection].filter((key) => visibleKeys.has(key))));}+ // A hidden anchor goes too: else clearing the search brings it back, and the next shift click+ // reaches from an entry the selection already lost.+ useEffect(() => {+ if (selectionAnchor.current && !visibleKeys.has(selectionAnchor.current)) {+ selectionAnchor.current = null;+ }+ }, [visibleKeys]);const previewItem = search.item ? (items.find((item) => item.id === search.item) ?? null) : null;const previewId = previewItem?.id ?? null;@@ -641,15 +659,54 @@ function LibraryView({ search }: { search: LibrarySearch }) {};};- const cardSelection = {- selection,- toggle: (key: string) =>- setSelection((current) => {- const next = new Set(current);- if (!next.delete(key)) next.add(key);- return next;- }),+ // A shift click sets the whole range to the clicked entry's new state, as in Chats.+ const toggleSelected = (key: string, range = false) => {+ const anchor = selectionAnchor.current;+ const keys = range && anchor ? rangeBetween(orderedKeys, anchor, key) : [key];+ const on = !selection.has(key);+ const next = new Set(selection);+ for (const each of keys) {+ if (on) next.add(each);+ else next.delete(each);+ }+ setSelectionState(next);+ selectionAnchor.current = next.size > 0 ? key : null;};+ const selectAll = () => setSelection(new Set(orderedKeys));+ const selectionBar = useRef<HTMLDivElement>(null);++ const cardSelection = { selection, toggle: toggleSelected };++ // Chats return their own view below, which has its own select all and Escape.+ const showsChats = tab === "chats" && !folderId;+ const selecting = selection.size > 0;+ // Cmd/Ctrl+A selects everything shown and Escape clears it, outside text fields. Both stand down+ // while a menu or dialog (the preview among them) is open, since the selection is behind it.+ // Passive on Escape, as Chats is: a menu closing on it has already prevented the default.+ useEffect(() => {+ if (showsChats || (!selecting && orderedKeys.length === 0)) return;+ const onKey = (event: KeyboardEvent) => {+ if (event.defaultPrevented) return;+ const target = event.target;+ if (target instanceof HTMLElement && target.closest("input, textarea, select, [contenteditable]")) {+ return;+ }+ if (document.querySelector('[role="menu"], [role="dialog"], [role="alertdialog"]')) return;+ const mod = isMacPlatform() ? event.metaKey : event.ctrlKey;+ // By the letter typed, or by the key's position on a layout that types no Latin letter.+ const isA = /^[a-z]$/i.test(event.key) ? event.key.toLowerCase() === "a" : event.code === "KeyA";+ if (mod && !event.altKey && !event.shiftKey && isA) {+ if (orderedKeys.length === 0) return;+ event.preventDefault();+ setSelection(new Set(orderedKeys));+ } else if (event.key === "Escape" && selecting) {+ if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;+ setSelection(new Set());+ }+ };+ window.addEventListener("keydown", onKey);+ return () => window.removeEventListener("keydown", onKey);+ }, [showsChats, selecting, orderedKeys, setSelection]);const selectedTargets = (): LibraryTarget[] => {const out: LibraryTarget[] = [];@@ -795,6 +852,7 @@ function LibraryView({ search }: { search: LibrarySearch }) {counts={counts}selection={selection}onSelectionChange={setSelection}+ onToggle={toggleSelected}sort={sort}onSortChange={(key) => go({ ...search, sort: sortParam(nextSort(sort, key)) }, true)}activity={false}@@ -878,6 +936,7 @@ function LibraryView({ search }: { search: LibrarySearch }) {counts={counts}selection={selection}onSelectionChange={setSelection}+ onToggle={toggleSelected}sort={sort}onSortChange={(key) => go({ ...search, sort: sortParam(nextSort(sort, key)) }, true)}activity={tab === "suggested" && !folderId}@@ -1009,9 +1068,36 @@ function LibraryView({ search }: { search: LibrarySearch }) {)}{selectedCount > 0 && (- <div className="fixed bottom-8 left-1/2 z-30 flex -translate-x-1/2 items-center gap-2 rounded-full bg-sidebar py-2 pl-6 pr-2 text-sidebar-foreground shadow-[0_2px_8px_-2px_rgba(0,0,0,0.16)] dark:shadow-[0_8px_28px_-6px_var(--background)]">- <span className="mr-4 whitespace-nowrap text-sm font-medium">- {t("shell.selection.countSelected", { count: selectedCount })}+ // Sized to its pills, and scrolls sideways rather than squashing them in a narrow window.+ <div+ ref={selectionBar}+ role="toolbar"+ aria-label={t("library.selection.countOfTotal", { count: selectedCount, total: orderedKeys.length })}+ tabIndex={-1}+ className="fixed bottom-8 left-1/2 z-30 flex w-max max-w-[calc(100vw-2rem)] -translate-x-1/2 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>*]:shrink-0 items-center gap-2 rounded-full bg-sidebar py-2 pl-6 pr-2 text-sidebar-foreground shadow-[0_2px_8px_-2px_rgba(0,0,0,0.16)] outline-none focus-visible:ring-2 focus-visible:ring-ring dark:shadow-[0_8px_28px_-6px_var(--background)]"+ >+ <span className="mr-4 flex items-center whitespace-nowrap text-sm font-medium">+ <span aria-live="polite">+ {t("library.selection.countOfTotal", { count: selectedCount, total: orderedKeys.length })}+ </span>+ {selectedCount < orderedKeys.length && (+ <>+ <span aria-hidden className="mx-2 text-muted-foreground">+ ·+ </span>+ <button+ type="button"+ // The link goes once everything is selected, so focus moves to the bar first.+ onClick={() => {+ selectAll();+ selectionBar.current?.focus();+ }}+ className="rounded-sm underline decoration-muted-foreground underline-offset-[3px] outline-none transition-colors hover:decoration-current focus-visible:ring-2 focus-visible:ring-ring"+ >+ {t("library.selection.selectAll")}+ </button>+ </>+ )}</span><buttontype="button"diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.tsindex 22ce20f19f2..6e482ef2f2b 100644--- a/studio/frontend/src/i18n/locales/ar.ts+++ b/studio/frontend/src/i18n/locales/ar.ts@@ -4004,6 +4004,8 @@ export const ar = {selection: {startChat: "بدء محادثة",move: "نقل",+ selectAll: "تحديد الكل",+ countOfTotal: "{count} من {total} محددة",clear: "مسح التحديد",},menu: {diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.tsindex b02defe0fa6..e61373d99d9 100644--- a/studio/frontend/src/i18n/locales/de.ts+++ b/studio/frontend/src/i18n/locales/de.ts@@ -4076,6 +4076,8 @@ export const de = {selection: {startChat: "Chat starten",move: "Verschieben",+ selectAll: "Alle auswählen",+ countOfTotal: "{count} von {total} ausgewählt",clear: "Auswahl aufheben",},menu: {diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex 9ce5398580d..d4fd075d72b 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -4034,6 +4034,9 @@ export const en = {selection: {startChat: "Start chat",move: "Move",+ // The bar's count, with the select all link beside it; {total} is everything currently shown.+ selectAll: "Select all",+ countOfTotal: "{count} of {total} selected",clear: "Clear selection",},menu: {diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.tsindex 4c28e53939a..cf3d4fcbedd 100644--- a/studio/frontend/src/i18n/locales/es.ts+++ b/studio/frontend/src/i18n/locales/es.ts@@ -4075,6 +4075,8 @@ export const es = {selection: {startChat: "Iniciar chat",move: "Mover",+ selectAll: "Seleccionar todo",+ countOfTotal: "{count} de {total} seleccionados",clear: "Borrar selección",},menu: {diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.tsindex 2fb7c7eb283..6bfa7fe162b 100644--- a/studio/frontend/src/i18n/locales/fr.ts+++ b/studio/frontend/src/i18n/locales/fr.ts@@ -4087,6 +4087,8 @@ export const fr = {selection: {startChat: "Démarrer une discussion",move: "Déplacer",+ selectAll: "Tout sélectionner",+ countOfTotal: "{count} sur {total} sélectionnés",clear: "Effacer la sélection",},menu: {diff --git a/studio/frontend/src/i18n/locales/he.ts b/studio/frontend/src/i18n/locales/he.tsindex 518480741c3..5897fa51465 100644--- a/studio/frontend/src/i18n/locales/he.ts+++ b/studio/frontend/src/i18n/locales/he.ts@@ -4117,6 +4117,8 @@ export const he = {selection: {startChat: "התחל צ'אט",move: "העברה",+ selectAll: "בחר הכל",+ countOfTotal: "{count} מתוך {total} נבחרו",clear: "ניקוי הבחירה",},menu: {diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.tsindex 69b5ca50634..724830ee038 100644--- a/studio/frontend/src/i18n/locales/hi.ts+++ b/studio/frontend/src/i18n/locales/hi.ts@@ -4012,6 +4012,8 @@ export const hi = {selection: {startChat: "चैट शुरू करें",move: "ले जाएँ",+ selectAll: "सभी चुनें",+ countOfTotal: "{total} में से {count} चुने गए",clear: "चयन हटाएँ",},menu: {diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.tsindex 7d10eb441b4..3341a49b08d 100644--- a/studio/frontend/src/i18n/locales/it.ts+++ b/studio/frontend/src/i18n/locales/it.ts@@ -4077,6 +4077,8 @@ export const it = {selection: {startChat: "Avvia chat",move: "Sposta",+ selectAll: "Seleziona tutto",+ countOfTotal: "{count} di {total} selezionate",clear: "Annulla selezione",},menu: {diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.tsindex 1a56c3d1c03..a8f8301e110 100644--- a/studio/frontend/src/i18n/locales/ja.ts+++ b/studio/frontend/src/i18n/locales/ja.ts@@ -3952,6 +3952,8 @@ export const ja = {selection: {startChat: "チャットを開始",move: "移動",+ selectAll: "すべて選択",+ countOfTotal: "{total} 件中 {count} 件選択中",clear: "選択を解除",},menu: {diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.tsindex e9bd7e8a7f8..426eab0c197 100644--- a/studio/frontend/src/i18n/locales/ko.ts+++ b/studio/frontend/src/i18n/locales/ko.ts@@ -3995,6 +3995,8 @@ export const ko = {selection: {startChat: "채팅 시작",move: "이동",+ selectAll: "모두 선택",+ countOfTotal: "{total}개 중 {count}개 선택됨",clear: "선택 해제",},menu: {diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.tsindex 16ddb7da6b2..d0e66ca8809 100644--- a/studio/frontend/src/i18n/locales/pt-br.ts+++ b/studio/frontend/src/i18n/locales/pt-br.ts@@ -4035,6 +4035,8 @@ export const ptBR = {selection: {startChat: "Iniciar chat",move: "Mover",+ selectAll: "Selecionar tudo",+ countOfTotal: "{count} de {total} selecionadas",clear: "Limpar seleção",},menu: {diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.tsindex 1bc9be93a4c..3541f051770 100644--- a/studio/frontend/src/i18n/locales/ru.ts+++ b/studio/frontend/src/i18n/locales/ru.ts@@ -4031,6 +4031,8 @@ export const ru = {selection: {startChat: "Начать чат",move: "Переместить",+ selectAll: "Выбрать все",+ countOfTotal: "Выбрано: {count} из {total}",clear: "Снять выделение",},menu: {diff --git a/studio/frontend/src/i18n/locales/sv.ts b/studio/frontend/src/i18n/locales/sv.tsindex 0ee1be9a3cd..38d508f10cb 100644--- a/studio/frontend/src/i18n/locales/sv.ts+++ b/studio/frontend/src/i18n/locales/sv.ts@@ -4257,6 +4257,8 @@ export const sv = {selection: {startChat: "Starta chatt",move: "Flytta",+ selectAll: "Markera alla",+ countOfTotal: "{count} av {total} markerade",clear: "Rensa markering",},menu: {diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.tsindex d591034a765..d9523b6e745 100644--- a/studio/frontend/src/i18n/locales/zh-CN.ts+++ b/studio/frontend/src/i18n/locales/zh-CN.ts@@ -3909,6 +3909,8 @@ export const zhCN = {selection: {startChat: "开始聊天",move: "移动",+ selectAll: "全选",+ countOfTotal: "已选择 {count} 个,共 {total} 个",clear: "清除选择",},menu: {