Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(gallery): a typed folder name that exists moves into that folder (FEHLER-D3 #1)

purplec8c432a50bbf
diff --git a/src/components/create/experimental/GalleryFolders.tsx b/src/components/create/experimental/GalleryFolders.tsx
index 01f1633e..45e6c6b3 100644
--- a/src/components/create/experimental/GalleryFolders.tsx
+++ b/src/components/create/experimental/GalleryFolders.tsx
@@ -20,7 +20,10 @@ export function OnBody({ children }: { children: ReactNode }) {
}
const FIELD =
- 'flex-1 min-w-0 h-[var(--control-h-md)] px-2.5 rounded-[var(--radius-control)] bg-white/[0.04] border border-white/[0.08] focus:border-white/20 outline-none t-control text-gray-100'
+ 'h-[var(--control-h-md)] px-2.5 rounded-[var(--radius-control)] bg-white/[0.04] border border-white/[0.08] focus:border-white/20 outline-none t-control text-gray-100'
+/** A field in a row next to a button. In the column of the move dialog
+ * flex-1 shrank its height to the text (FEHLER-D3 #1, side finding). */
+const ROW_FIELD = `flex-1 min-w-0 ${FIELD}`
/** The filter at the top of the gallery: "All" and every folder, with counts,
* and the button that manages the folders. */
@@ -103,7 +106,7 @@ function ManageFolders() {
else e.currentTarget.value = f.name
}}
onKeyDown={(e) => { if (e.key === 'Enter') e.currentTarget.blur() }}
- className={FIELD}
+ className={ROW_FIELD}
/>
<span className="t-mono text-gray-500 w-8 text-right">{counts.get(f.id) ?? 0}</span>
<button
@@ -127,7 +130,7 @@ function ManageFolders() {
disabled={full}
onChange={(e) => setName(e.target.value)}
onKeyDown={(e) => { if (e.key === 'Enter') create() }}
- className={FIELD}
+ className={ROW_FIELD}
/>
<ModalButton onClick={create} disabled={full || !name.trim()}>Add</ModalButton>
</div>
@@ -179,7 +182,7 @@ function MoveToFolder({ ids, onClose }: { ids: readonly string[]; onClose: () =>
disabled={full}
onChange={(e) => setName(e.target.value)}
onKeyDown={(e) => { if (e.key === 'Enter') go() }}
- className={FIELD}
+ className={`w-full ${FIELD}`}
/>
<ModalActions>
<ModalButton variant="quiet" onClick={onClose}>Cancel</ModalButton>
diff --git a/src/components/create/experimental/__tests__/galerie-ordner-doppelt.test.tsx b/src/components/create/experimental/__tests__/galerie-ordner-doppelt.test.tsx
new file mode 100644
index 00000000..d22b1d10
--- /dev/null
+++ b/src/components/create/experimental/__tests__/galerie-ordner-doppelt.test.tsx
@@ -0,0 +1,76 @@
+// @vitest-environment jsdom
+/**
+ * FEHLER-D3 #1 (I1, Box-Runde 01.11.2026, Windows): "Move to folder" with a
+ * typed name that already exists made one more folder of that name each time;
+ * five moves to "Win Test" left five folders "Win Test" with one picture each.
+ * addGalleryFolder never looked at the names it had. Since 3.0.7, more often
+ * since D3 (several at once, from the large view).
+ *
+ * Side finding of the same run: the name field of the dialog was visibly
+ * flatter than the folder picker above it (18 px against 37 px, WebKit). It
+ * carried flex-1, meant for the rows of "Gallery folders", and in the
+ * dialog's column that shrank its height.
+ *
+ * Run: npx vitest run src/components/create/experimental/__tests__/galerie-ordner-doppelt.test.tsx
+ */
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+import { useCreateStore, type GalleryItem } from '../../../../stores/createStore'
+import { MoveToFolderModal } from '../GalleryFolders'
+
+const ITEM = (id: string): GalleryItem => ({
+ id, type: 'image', filename: `${id}.png`, subfolder: '', prompt: `prompt ${id}`, negativePrompt: '',
+ model: 'm.safetensors', modelType: 'sdxl', seed: 1, steps: 20, cfgScale: 5, sampler: 'euler',
+ scheduler: 'normal', width: 512, height: 512, batchSize: 1, createdAt: 1,
+})
+const st = () => useCreateStore.getState()
+
+beforeEach(() => {
+ useCreateStore.setState({
+ gallery: [ITEM('a'), ITEM('b'), ITEM('c')],
+ galleryFolders: [{ id: 'f-1', name: 'D3 Box' }],
+ galleryFolderOpen: null,
+ })
+})
+afterEach(() => { cleanup() })
+
+describe('addGalleryFolder', () => {
+ it('a name that exists gives back that folder instead of a second one', () => {
+ const first = st().addGalleryFolder('Win Test')
+ expect(st().addGalleryFolder('Win Test')).toBe(first)
+ expect(st().addGalleryFolder(' win test ')).toBe(first)
+ expect(st().addGalleryFolder('d3 box')).toBe('f-1')
+ expect(st().galleryFolders.map((f) => f.name)).toEqual(['D3 Box', 'Win Test'])
+ })
+
+ it('an existing name is found even when the list is full', () => {
+ useCreateStore.setState({ galleryFolders: Array.from({ length: 50 }, (_, i) => ({ id: `f-${i}`, name: `F ${i}` })) })
+ expect(st().addGalleryFolder('f 7')).toBe('f-7')
+ })
+})
+
+describe('the move dialog', () => {
+ function moveByName(id: string, name: string) {
+ const { unmount } = render(<MoveToFolderModal ids={[id]} onClose={() => {}} />)
+ fireEvent.change(screen.getByRole('textbox', { name: 'New folder name' }), { target: { value: name } })
+ fireEvent.click(screen.getByRole('button', { name: 'Move' }))
+ unmount()
+ }
+
+ it('the same typed name three times: one folder with three pictures', () => {
+ moveByName('a', 'Win Test')
+ moveByName('b', 'Win Test')
+ moveByName('c', 'win test')
+ const named = st().galleryFolders.filter((f) => f.name.toLowerCase() === 'win test')
+ expect(named).toHaveLength(1)
+ expect(st().gallery.every((g) => g.folderId === named[0].id)).toBe(true)
+ })
+
+ it('the name field keeps the height of the picker above it (no flex-1 in the column)', () => {
+ render(<MoveToFolderModal ids={['a']} onClose={() => {}} />)
+ const field = screen.getByRole('textbox', { name: 'New folder name' })
+ expect(field.className.split(/\s+/)).not.toContain('flex-1')
+ expect(field.className).toContain('h-[var(--control-h-md)]')
+ })
+})
diff --git a/src/stores/createStore.ts b/src/stores/createStore.ts
index 7589fad9..e73deb4a 100644
--- a/src/stores/createStore.ts
+++ b/src/stores/createStore.ts
@@ -737,7 +737,8 @@ export interface CreateState {
mergeGallery: (items: GalleryItem[]) => void
removeFromGallery: (id: string) => void
clearGallery: () => void
- /** Make a folder. Returns its id, or null for an empty name or a full list. */
+ /** Make a folder. Returns its id (the one already there for a name it has,
+ * in any case), or null for an empty name or a full list. */
addGalleryFolder: (name: string) => string | null
renameGalleryFolder: (id: string, name: string) => void
/** Remove a folder. Its entries stay in the gallery and go back to "All";
@@ -1796,7 +1797,12 @@ export const useCreateStore = create<CreateState>()(
addGalleryFolder: (name) => {
const clean = cleanFolderName(name)
const s = get()
- if (!clean || s.galleryFolders.length >= FOLDER_CAP) return null
+ if (!clean) return null
+ // FEHLER-D3 #1: a name that is there already is that folder. Every
+ // typed "Win Test" used to make one more folder of the same name.
+ const same = s.galleryFolders.find((f) => f.name.toLowerCase() === clean.toLowerCase())
+ if (same) return same.id
+ if (s.galleryFolders.length >= FOLDER_CAP) return null
const id = newFolderId(s.galleryFolders)
set({ galleryFolders: [...s.galleryFolders, { id, name: clean }] })
return id