Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.
TypeScript ai-photo-editorcomfyui-alternativegenerative-fillimage-editingimage-generationinpaintinglinuxlocal-aimacosmcpmcp-servernano-banana-alternativeofflinephoto-editorprivacyqwen-imageqwen-image-2-1stable-diffusion-cppvulkanwindows
App: gallery preview with browsing, full screen follows the timeline, keep names when renaming
Gabriele Lozupone71e1a0d53fbd
diff --git a/src/components/Compare.tsx b/src/components/Compare.tsxindex e53b360..2b36fef 100644--- a/src/components/Compare.tsx+++ b/src/components/Compare.tsx@@ -25,7 +25,7 @@ const DIFF_SIDE = 1024;const isTyping = (t: EventTarget | null) => t instanceof HTMLElement && (t.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(t.tagName));/** The result with the selected comparison view, sized to fit the stage (or the screen). */-export function CompareFrame({ g, base, fullscreen = false }: { g: GenerationRecord; base: CompareBase; fullscreen?: boolean }) {+export function CompareFrame({ g, base, fullscreen = false, onFullscreen }: { g: GenerationRecord; base: CompareBase; fullscreen?: boolean; onFullscreen?: () => void }) {const mode = useStore((s) => s.compare);const flickerMs = useStore((s) => s.flickerMs);const { ref, box } = useFit(g.width / g.height);@@ -123,23 +123,25 @@ export function CompareFrame({ g, base, fullscreen = false }: { g: GenerationRec</div>)}{!fullscreen && (- <FullscreenButton- hint="Hold B for the original"- content={- <>- <CompareFrame g={g} base={base} fullscreen />- <div className="viewer-compare-bar">- <CompareBar />- </div>- </>- }- />+ <FullscreenButton hint="Hold B for the original" onOpen={onFullscreen} content={<CompareFullscreen g={g} base={base} />} />)}</div></div>);}+/** What full screen shows for a result with an original: the comparison and its controls. */+export function CompareFullscreen({ g, base }: { g: GenerationRecord; base: CompareBase }) {+ return (+ <>+ <CompareFrame g={g} base={base} fullscreen />+ <div className="viewer-compare-bar">+ <CompareBar />+ </div>+ </>+ );+}+/** Highlights what changed: dimmed result, changed pixels in red. */function DiffCanvas({ after, before, rect }: { after: string; before: string; rect: CompareBase["rect"] }) {const ref = useRef<HTMLCanvasElement>(null);diff --git a/src/components/Gallery.tsx b/src/components/Gallery.tsxindex 4e5562d..77dd673 100644--- a/src/components/Gallery.tsx+++ b/src/components/Gallery.tsx@@ -1,12 +1,16 @@-import { ArrowLeft, Heart, Loader2, Search, Trash2 } from "lucide-react";-import { useCallback, useEffect, useRef, useState } from "react";+import { ArrowLeft, FolderOpen, Heart, Loader2, Maximize2, Search, Trash2 } from "lucide-react";+import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { api, urls } from "../lib/api";import { native } from "../lib/native";import { forgetGeneration, openGeneration, setState, toastError, useStore } from "../lib/store";+import { MODE_LABEL, neighbourAfterRemoval, previewIndex } from "../lib/logic";import type { GenerationRecord } from "../lib/types";import { IconButton, Seg } from "./ui";+import { Fullscreen, isTyping, NavArrows, navKey, useMouseActive, ZoomImage, type ViewerNav } from "./Viewer";const PAGE = 60;+/** Most images the server returns in one request. */+const MAX_PAGE = 500;export function Gallery() {const version = useStore((s) => s.galleryVersion);@@ -17,14 +21,29 @@ export function Gallery() {const [total, setTotal] = useState(0);const [loading, setLoading] = useState(false);const gridRef = useRef<HTMLDivElement>(null);+ // The image open in the preview, by id (the list can shift under it), with its last+ // position for when it leaves the list.+ const [view, setView] = useState<{ id: string; at: number } | null>(null);+ const ids = useMemo(() => items.map((g) => g.id), [items]);+ const index = view ? previewIndex(ids, view.id, view.at) : null;+ const loaded = useRef(0);+ loaded.current = items.length;+ /** Loads `count` images from `offset` (the first page replaces the list). */const load = useCallback(- async (offset: number) => {+ async (offset: number, count = PAGE) => {setLoading(true);try {- const r = await api.gallery({ q, favorites, sort, limit: PAGE, offset });- setItems((prev) => (offset === 0 ? r.items : [...prev, ...r.items]));- setTotal(r.total);+ const got: GenerationRecord[] = [];+ let all = 0;+ do {+ const r = await api.gallery({ q, favorites, sort, limit: Math.min(MAX_PAGE, count - got.length), offset: offset + got.length });+ got.push(...r.items);+ all = r.total;+ if (r.items.length === 0) break;+ } while (got.length < count && offset + got.length < all);+ setItems((prev) => (offset === 0 ? got : [...prev, ...got]));+ setTotal(all);} catch (e) {toastError(e);} finally {@@ -34,8 +53,13 @@ export function Gallery() {[q, favorites, sort],);+ // A new search, filter or sort starts from the first page; a refresh (a new image was made)+ // reloads as many as were loaded, so the image in the preview stays in the list.+ const lastLoad = useRef(load);useEffect(() => {- const t = window.setTimeout(() => load(0), q ? 250 : 0);+ const refresh = lastLoad.current === load;+ lastLoad.current = load;+ const t = window.setTimeout(() => load(0, refresh ? Math.max(PAGE, loaded.current) : PAGE), q && !refresh ? 250 : 0);return () => window.clearTimeout(t);}, [load, version, q]);@@ -45,11 +69,37 @@ export function Gallery() {return () => window.removeEventListener("keydown", onKey);}, []);+ // A new search or filter closes the preview. When the image it shows has left the list,+ // it moves onto the one now at that position (back to the grid when nothing is left).+ useEffect(() => setView(null), [q, favorites, sort]);+ useEffect(() => {+ if (!view || loading || ids.includes(view.id)) return;+ setView(index === null ? null : { id: ids[index], at: index });+ }, [view, index, ids, loading]);++ // Browsing near the end of what is loaded fetches the next page.+ useEffect(() => {+ if (index !== null && !loading && items.length < total && index >= items.length - 3) load(items.length);+ }, [index, loading, items.length, total, load]);++ const go = useCallback((i: number) => ids[i] && setView({ id: ids[i], at: i }), [ids]);++ /** Before an image leaves the list: if the preview shows it, move to its neighbour. */+ const idsNow = useRef(ids);+ idsNow.current = ids;+ const leaving = (id: string) =>+ setView((v) => {+ if (v?.id !== id) return v;+ const next = neighbourAfterRemoval(idsNow.current, id);+ return next ? { id: next, at: v.at } : null;+ });+const reopen = (g: GenerationRecord) => openGeneration(g).catch(toastError);const toggleFav = async (g: GenerationRecord) => {try {const r = await api.setFavorite(g.id, !g.favorite);+ if (favorites && !r.favorite) leaving(g.id);setItems((list) => (favorites && !r.favorite ? list.filter((x) => x.id !== g.id) : list.map((x) => (x.id === g.id ? r : x))));} catch (e) {toastError(e);@@ -59,6 +109,7 @@ export function Gallery() {const remove = async (g: GenerationRecord) => {try {await api.deleteGeneration(g.id);+ leaving(g.id);setItems((list) => list.filter((x) => x.id !== g.id));setTotal((t) => t - 1);forgetGeneration(g.id);@@ -103,8 +154,16 @@ export function Gallery() {if (!loading && items.length < total && el.scrollTop + el.clientHeight > el.scrollHeight - 400) load(items.length);}}>- {items.map((g) => (- <div key={g.id} className="card" onClick={() => reopen(g)} title={g.prompt}>+ {items.map((g, i) => (+ <div+ key={g.id}+ className="card"+ onClick={() => {+ (document.activeElement as HTMLElement | null)?.blur();+ setView({ id: g.id, at: i });+ }}+ title={g.prompt}+ ><img src={urls.genThumb(g.id)} alt="" loading="lazy" draggable={false} /><div className={`card-actions ${g.favorite ? "fav" : ""}`} onClick={(e) => e.stopPropagation()}><button title={g.favorite ? "Remove from favorites" : "Favorite"} onClick={() => toggleFav(g)}>@@ -129,6 +188,106 @@ export function Gallery() {</div>)}</div>+ {index !== null && view && (+ <Preview+ g={items[index]}+ index={index}+ total={total}+ count={items.length}+ onGo={go}+ onClose={() => setView(null)}+ onOpen={reopen}+ onFavorite={toggleFav}+ onDelete={remove}+ />+ )}+ </div>+ );+}++/** One gallery image, large, over the grid (which keeps its scroll position underneath):+ * arrows browse the gallery, F goes full screen, Enter opens it in its project. */+function Preview(props: {+ g: GenerationRecord;+ index: number;+ total: number;+ count: number;+ onGo: (i: number) => void;+ onClose: () => void;+ onOpen: (g: GenerationRecord) => void;+ onFavorite: (g: GenerationRecord) => void;+ onDelete: (g: GenerationRecord) => void;+}) {+ const { g, index, total, count, onGo, onClose, onOpen } = props;+ const [full, setFull] = useState(false);+ const [active, wake] = useMouseActive();+ const nav = useMemo<ViewerNav>(+ () => ({+ prev: index > 0 ? () => onGo(index - 1) : undefined,+ next: index < count - 1 ? () => onGo(index + 1) : undefined,+ pos: `${index + 1} / ${total}`,+ }),+ [index, count, total, onGo],+ );+ const del = async () => {+ if (await native.confirm("Delete this image from the gallery and disk?", "Delete")) props.onDelete(g);+ };++ useEffect(() => {+ if (full) return; // full screen has its own keys+ const down = (e: KeyboardEvent) => {+ if (isTyping(e.target)) return;+ const k = e.key.toLowerCase();+ if (e.key === "Escape") onClose();+ else if (k === "f" && !e.repeat && !e.ctrlKey && !e.metaKey && !e.altKey) setFull(true);+ else if (e.key === "Enter") onOpen(g);+ else if (!navKey(e, nav)) return;+ e.preventDefault();+ // Captured before the gallery's own Esc, which would close the whole gallery.+ e.stopPropagation();+ };+ window.addEventListener("keydown", down, true);+ return () => window.removeEventListener("keydown", down, true);+ }, [full, nav, g, onClose, onOpen]);++ return (+ <div className="preview" role="dialog" aria-label="Image preview">+ <div className="overlay-head">+ <IconButton title="Back to all images (Esc)" onClick={onClose}>+ <ArrowLeft size={18} />+ </IconButton>+ <span className="preview-prompt" title={g.prompt}>+ {g.prompt || MODE_LABEL[g.mode]}+ </span>+ <span className="muted preview-pos">{nav.pos}</span>+ </div>+ <div className="preview-stage" onPointerMove={wake} onMouseEnter={wake}>+ <img key={g.id} className="preview-img" src={urls.gen(g.id)} alt={g.prompt} draggable={false} onDoubleClick={() => setFull(true)} />+ <NavArrows nav={nav} visible={active} />+ </div>+ <div className="preview-bar">+ <span className="dims muted">+ {g.width}×{g.height}+ </span>+ <span className="spacer" />+ <IconButton title={g.favorite ? "Remove from favorites" : "Favorite"} active={g.favorite} onClick={() => props.onFavorite(g)}>+ <Heart size={17} fill={g.favorite ? "currentColor" : "none"} />+ </IconButton>+ <IconButton title="Delete" onClick={del}>+ <Trash2 size={17} />+ </IconButton>+ <IconButton title="Full screen (F)" onClick={() => setFull(true)}>+ <Maximize2 size={17} />+ </IconButton>+ <button className="btn primary" title="Open in its project to keep editing (Enter)" onClick={() => onOpen(g)}>+ <FolderOpen size={15} /> Open in project+ </button>+ </div>+ {full && (+ <Fullscreen hint="Click to zoom to 100 %" onClose={() => setFull(false)} nav={nav}>+ <ZoomImage key={g.id} src={urls.gen(g.id)} alt={g.prompt} />+ </Fullscreen>+ )}</div>);}diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsxindex 4f8b020..c327c82 100644--- a/src/components/Sidebar.tsx+++ b/src/components/Sidebar.tsx@@ -50,7 +50,7 @@ Double-click or F2 to rename`}<span className="cover">{p.cover && <img src={urls.sourceThumb(p.cover)} alt="" draggable={false} loading="lazy" />}</span><span className="proj-text">{renaming === p.id ? (- <NameField value={p.named ? p.title : ""} onSave={(v) => renameProject(p.id, v)} onDone={() => setRenaming(null)} />+ <NameField value={p.title} onSave={(v) => renameProject(p.id, v)} onDone={() => setRenaming(null)} />) : (<span className="proj-title">{p.title}</span>)}@@ -92,7 +92,7 @@ export function ProjectTitle() {const id = useStore((s) => s.projectId);const meta = useStore((s) => s.projects.find((p) => p.id === s.projectId));const [editing, setEditing] = useState(false);- if (editing) return <NameField className="title-field" value={meta?.named ? meta.title : ""} onSave={(v) => renameProject(id, v)} onDone={() => setEditing(false)} />;+ if (editing) return <NameField className="title-field" value={meta?.title ?? ""} onSave={(v) => renameProject(id, v)} onDone={() => setEditing(false)} />;return (<button className={`project-title ${meta ? "" : "placeholder"}`} title="Rename project" onClick={() => setEditing(true)}>{meta?.title ?? "Untitled project"}diff --git a/src/components/Stage.tsx b/src/components/Stage.tsxindex 65e0fc8..af7310b 100644--- a/src/components/Stage.tsx+++ b/src/components/Stage.tsx@@ -12,9 +12,9 @@ import {addAsReference, cancelJob, focusPrompt, getState, itemSource, removeSessionItem, reusePrompt, selectedItem, selectItem, sessionLabels, sessionLinks, setState, submitRequest, toastError, toastInfo, useStore, type SessionItem,} from "../lib/store";import type { GenerationRecord, JobView, Mode, Size } from "../lib/types";-import { CompareFrame } from "./Compare";+import { CompareFrame, CompareFullscreen } from "./Compare";import { IconButton, Popover, useFit } from "./ui";-import { FullscreenButton, ZoomImage } from "./Viewer";+import { Fullscreen, FullscreenButton, isTyping, ZoomImage, type ViewerNav } from "./Viewer";import { fileManager, shortcut } from "../lib/platform";export const MODE_ICON: Record<Mode, React.ReactNode> = {@@ -370,14 +370,14 @@ function InputActions({ item }: { item: SessionItem }) {/** A result or input fitted to the stage (never enlarged past its own size), with the* full-screen button in its top-right corner. */-function PlainFrame({ src, alt, w, h }: { src: string; alt: string; w: number; h: number }) {+function PlainFrame({ src, alt, w, h, onFullscreen }: { src: string; alt: string; w: number; h: number; onFullscreen: () => void }) {const { ref, box } = useFit(w / h);const bw = Math.min(box.w, w);return (<div className="stage-frame" ref={ref}><div className="image-box" style={{ width: bw, height: bw * (h / w) }}><img className="stage-img fill" src={src} alt={alt} draggable={false} />- <FullscreenButton hint="Click to zoom to 100 %" content={<ZoomImage src={src} alt={alt} />} />+ <FullscreenButton onOpen={onFullscreen} /></div></div>);@@ -638,6 +638,45 @@ function Ring({ frac }: { frac: number }) {);}+/** A version that has a picture to show (not a job still running or one that failed). */+const viewable = (i: SessionItem) => !!(i.gen || i.input);++/** Full screen for the selected version: follows the selection, and ←/→ (or the arrows on+ * the sides) step through the versions of the timeline without leaving it. */+function StageFullscreen({ item, session, showOriginal, onClose }: { item: SessionItem; session: SessionItem[]; showOriginal: boolean; onClose: () => void }) {+ const nav = useMemo<ViewerNav>(() => {+ const at = session.findIndex((i) => i.key === item.key);+ const step = (d: number) => {+ for (let j = at + d; j >= 0 && j < session.length; j += d) {+ const key = session[j].key;+ if (viewable(session[j])) return () => selectItem(key);+ }+ return undefined;+ };+ const shown = session.filter(viewable);+ return { prev: step(-1), next: step(1), pos: `${shown.findIndex((i) => i.key === item.key) + 1} / ${shown.length}` };+ }, [item.key, session]);++ const g = item.gen;+ const base = g ? compareBase(g) : null;+ const from = g?.pipeline?.original_path ? g.pipeline.enlarged_from : null;+ let content: React.ReactNode;+ let hint = "Click to zoom to 100 %";+ if (g && from && showOriginal) content = <ZoomImage key={`original-${g.id}`} src={urls.genOriginal(g.id)} alt={`${g.prompt} (before upscaling)`} />;+ else if (g && base) {+ content = <CompareFullscreen key={g.id} g={g} base={base} />;+ hint = "Hold B for the original";+ } else {+ const src = g ? urls.gen(g.id) : urls.input(item.input!.id);+ content = <ZoomImage key={src} src={src} alt={g?.prompt ?? item.input?.original_name ?? ""} />;+ }+ return (+ <Fullscreen hint={hint} onClose={onClose} nav={nav}>+ {content}+ </Fullscreen>+ );+}+export function Stage() {const item = useStore(selectedItem);const session = useStore((s) => s.session);@@ -645,6 +684,29 @@ export function Stage() {const labels = useMemo(() => sessionLabels(session), [session]);// The result whose pre-upscale original is on screen instead of it.const [originalOf, setOriginalOf] = useState<string | null>(null);+ const [full, setFull] = useState(false);+ const canFull = !!item && viewable(item);++ // F opens full screen on the selected version (Esc or F again closes it).+ useEffect(() => {+ if (full || !canFull) return;+ const down = (e: KeyboardEvent) => {+ if (e.key.toLowerCase() !== "f" || e.repeat || e.ctrlKey || e.metaKey || e.altKey || isTyping(e.target) || getState().overlay) return;+ setFull(true);+ };+ window.addEventListener("keydown", down);+ return () => window.removeEventListener("keydown", down);+ }, [full, canFull]);++ // Nothing to show any more (the version was removed, or a new one is being made): leave full screen.+ useEffect(() => {+ if (full && !canFull) setFull(false);+ }, [full, canFull]);++ const fullscreen = full && canFull && item && (+ <StageFullscreen item={item} session={session} showOriginal={!!(item.gen && originalOf === item.gen.id)} onClose={() => setFull(false)} />+ );+ const openFull = () => setFull(true);if (!item) {return (@@ -677,11 +739,11 @@ export function Stage() {view = (<>{g && from && showOriginal ? (- <PlainFrame key={`original-${g.id}`} src={urls.genOriginal(g.id)} alt={`${g.prompt} (before upscaling)`} w={from.width} h={from.height} />+ <PlainFrame key={`original-${g.id}`} src={urls.genOriginal(g.id)} alt={`${g.prompt} (before upscaling)`} w={from.width} h={from.height} onFullscreen={openFull} />) : item.gen && base ? (- <CompareFrame key={`compare-${item.gen.id}`} g={item.gen} base={base} />+ <CompareFrame key={`compare-${item.gen.id}`} g={item.gen} base={base} onFullscreen={openFull} />) : (- <PlainFrame key={src} src={src} alt={item.gen?.prompt ?? item.input?.original_name ?? ""} w={w} h={h} />+ <PlainFrame key={src} src={src} alt={item.gen?.prompt ?? item.input?.original_name ?? ""} w={w} h={h} onFullscreen={openFull} />)}<StageBar item={item} label={labels[item.key]} showOriginal={showOriginal} setShowOriginal={(on) => setOriginalOf(on && g ? g.id : null)} /></>@@ -692,6 +754,7 @@ export function Stage() {<div className="stage">{view}<Timeline labels={labels} />+ {fullscreen}</div>);}diff --git a/src/components/Viewer.tsx b/src/components/Viewer.tsxindex c52abe2..33712b1 100644--- a/src/components/Viewer.tsx+++ b/src/components/Viewer.tsx@@ -1,25 +1,35 @@// Full-screen viewing: a shell that takes the window full screen and shows any content// (the live before/after comparison, or a zoomable image).-import { Maximize2, X } from "lucide-react";-import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";+import { ChevronLeft, ChevronRight, Maximize2, X } from "lucide-react";+import { useCallback, useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";import { createPortal } from "react-dom";import { native } from "../lib/native";-const isTyping = (t: EventTarget | null) => t instanceof HTMLElement && (t.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(t.tagName));+export const isTyping = (t: EventTarget | null) => t instanceof HTMLElement && (t.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(t.tagName));++/** Steps through a list while viewing: `prev` / `next` are absent at the ends; `pos` reads+ * like "3 / 12". */+export interface ViewerNav {+ prev?: () => void;+ next?: () => void;+ pos?: string;+}/** Button for the top-right corner of an image; F also opens it. `content` is what to show- * full screen; `hint` is shown next to the close button. */-export function FullscreenButton({ content, hint }: { content: ReactNode; hint?: string }) {+ * full screen; `hint` is shown next to the close button. With `onOpen` the parent owns the+ * full-screen view (and the F key) and the button only asks for it. */+export function FullscreenButton({ content, hint, onOpen }: { content?: ReactNode; hint?: string; onOpen?: () => void }) {const [open, setOpen] = useState(false);+ const show = onOpen ?? (() => setOpen(true));useEffect(() => {- if (open) return;+ if (open || onOpen) return;const down = (e: KeyboardEvent) => {if (e.key.toLowerCase() === "f" && !e.repeat && !e.ctrlKey && !e.metaKey && !e.altKey && !isTyping(e.target)) setOpen(true);};window.addEventListener("keydown", down);return () => window.removeEventListener("keydown", down);- }, [open]);+ }, [open, onOpen]);return (<><button@@ -29,7 +39,7 @@ export function FullscreenButton({ content, hint }: { content: ReactNode; hint?:onPointerDown={(e) => e.stopPropagation()}onClick={(e) => {e.stopPropagation();- setOpen(true);+ show();}}onDoubleClick={(e) => e.stopPropagation()}>@@ -46,7 +56,61 @@ export function FullscreenButton({ content, hint }: { content: ReactNode; hint?:);}-function FullscreenShell({ children, hint, onClose }: { children: ReactNode; hint?: string; onClose: () => void }) {+/** The full-screen view as a portal, for parents that own it (see `FullscreenButton`). */+export function Fullscreen(props: { children: ReactNode; hint?: string; onClose: () => void; nav?: ViewerNav }) {+ return createPortal(<FullscreenShell {...props} />, document.body);+}++/** True while the mouse has moved in the last moment; `wake` goes on pointer move. */+export function useMouseActive(ms = 1800): [boolean, () => void] {+ const [active, setActive] = useState(false);+ const timer = useRef<number | undefined>(undefined);+ const wake = useCallback(() => {+ setActive(true);+ window.clearTimeout(timer.current);+ timer.current = window.setTimeout(() => setActive(false), ms);+ }, [ms]);+ useEffect(() => () => window.clearTimeout(timer.current), []);+ return [active, wake];+}++/** Previous / next buttons on the left and right edges of a picture. */+export function NavArrows({ nav, visible }: { nav: ViewerNav; visible: boolean }) {+ const btn = (side: "left" | "right", go: (() => void) | undefined) =>+ go && (+ <button+ className={`nav-arrow ${side} ${visible ? "" : "hidden"}`}+ title={side === "left" ? "Previous (←)" : "Next (→)"}+ aria-label={side === "left" ? "Previous image" : "Next image"}+ onClick={(e) => {+ e.stopPropagation();+ go();+ }}+ onPointerDown={(e) => e.stopPropagation()}+ onDoubleClick={(e) => e.stopPropagation()}+ >+ {side === "left" ? <ChevronLeft size={26} /> : <ChevronRight size={26} />}+ </button>+ );+ return (+ <>+ {btn("left", nav.prev)}+ {btn("right", nav.next)}+ </>+ );+}++/** ←/↑ and →/↓ call `nav`; returns true when the key was used. */+export function navKey(e: KeyboardEvent, nav: ViewerNav | undefined): boolean {+ if (!nav || e.ctrlKey || e.metaKey || e.altKey) return false;+ const go = e.key === "ArrowLeft" || e.key === "ArrowUp" ? nav.prev : e.key === "ArrowRight" || e.key === "ArrowDown" ? nav.next : undefined;+ if (!go) return false;+ go();+ return true;+}++function FullscreenShell({ children, hint, onClose, nav }: { children: ReactNode; hint?: string; onClose: () => void; nav?: ViewerNav }) {+ const [active, wake] = useMouseActive();// Real full screen for the window while open; restored on close unless it already was.useEffect(() => {let wasFull = false;@@ -71,11 +135,15 @@ function FullscreenShell({ children, hint, onClose }: { children: ReactNode; hine.preventDefault();e.stopPropagation();onClose();+ } else if (navKey(e, nav)) {+ // Captured here so the app's own arrow keys (which also browse versions) don't move twice.+ e.preventDefault();+ e.stopPropagation();}};window.addEventListener("keydown", down, true);return () => window.removeEventListener("keydown", down, true);- }, [onClose]);+ }, [onClose, nav]);// React events from a portal still bubble to its React parents: without this, a press// anywhere here reaches the stage image underneath (which captures the pointer for the@@ -87,7 +155,10 @@ function FullscreenShell({ children, hint, onClose }: { children: ReactNode; hinrole="dialog"aria-label="Full screen"onPointerDown={stop}- onPointerMove={stop}+ onPointerMove={(e) => {+ stop(e);+ wake();+ }}onPointerUp={stop}onPointerCancel={stop}onClick={stop}@@ -95,8 +166,10 @@ function FullscreenShell({ children, hint, onClose }: { children: ReactNode; hinonContextMenu={stop}>{children}+ {nav && <NavArrows nav={nav} visible={active} />}<div className="viewer-bar">- <span className="viewer-hint">{hint ? `${hint} · ` : ""}Esc to exit</span>+ {nav?.pos && <span className="viewer-tag">{nav.pos}</span>}+ <span className="viewer-hint">{hint ? `${hint} · ` : ""}{nav ? "← → to browse · " : ""}Esc to exit</span><button className="viewer-close" title="Exit full screen (Esc)" aria-label="Exit full screen" onClick={onClose}><X size={18} /></button>diff --git a/src/components/ui.tsx b/src/components/ui.tsxindex d2a57ee..bdb002d 100644--- a/src/components/ui.tsx+++ b/src/components/ui.tsx@@ -101,7 +101,12 @@ export function NameField(props: { value: string; onSave: (v: string) => void; oclassName={`name-field ${props.className ?? ""}`}value={v}autoFocus- onFocus={(e) => e.currentTarget.select()}+ // Caret at the end, nothing selected: typing adds to the name instead of replacing it.+ onFocus={(e) => {+ const n = e.currentTarget.value.length;+ e.currentTarget.setSelectionRange(n, n);+ e.currentTarget.scrollLeft = e.currentTarget.scrollWidth;+ }}onChange={(e) => setV(e.target.value)}onClick={(e) => e.stopPropagation()}onKeyDown={(e) => {diff --git a/src/lib/logic.test.ts b/src/lib/logic.test.tsindex ad80642..a152eb9 100644--- a/src/lib/logic.test.ts+++ b/src/lib/logic.test.ts@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";import {activeOverrides, buildRequest, compareBase, diffPixels, emptyComposer, expansionPixels, expansionPreset, jobFraction, jobLabel, moveRef, needsPrompt, normalizeQuality, persistentAdvanced, pipelineSummary,planPipeline, remainingSeconds, sizeForWidth, timeAgo, upscaleRequest, upscaleTargets, versionLabels, type Ref,- formatBytes, installItemShort, installItemText, installProgress, installStep, installTimeLeft, timelineLinks, undoTarget, aspectLabel, parseRatio, sizeForRatio, expandToRatio, expandToSize, arcLayout,+ neighbourAfterRemoval, previewIndex, formatBytes, installItemShort, installItemText, installProgress, installStep, installTimeLeft, timelineLinks, undoTarget, aspectLabel, parseRatio, sizeForRatio, expandToRatio, expandToSize, arcLayout,} from "./logic";import type { GenerationRecord, InstallItem, JobView, Plan } from "./types";@@ -366,3 +366,22 @@ describe("timeline arcs", () => {expect(p[0].dx1).toBe(0);});});++describe("gallery preview", () => {+ it("stays on the same image when the list shifts", () => {+ // A new image arrives at the top: the shown image moves down one place.+ expect(previewIndex(["a", "b", "c"], "b", 1)).toBe(1);+ expect(previewIndex(["new", "a", "b", "c"], "b", 1)).toBe(2);+ });+ it("falls back to the last position when the image is gone", () => {+ expect(previewIndex(["a", "c"], "b", 1)).toBe(1);+ expect(previewIndex(["a"], "b", 4)).toBe(0);+ expect(previewIndex([], "b", 0)).toBeNull();+ });+ it("moves to a neighbour on removal", () => {+ expect(neighbourAfterRemoval(["a", "b", "c"], "b")).toBe("c");+ expect(neighbourAfterRemoval(["a", "b", "c"], "c")).toBe("b");+ expect(neighbourAfterRemoval(["a"], "a")).toBeNull();+ expect(neighbourAfterRemoval(["a"], "x")).toBeNull();+ });+});diff --git a/src/lib/logic.ts b/src/lib/logic.tsindex 8966cd8..6142f28 100644--- a/src/lib/logic.ts+++ b/src/lib/logic.ts@@ -656,3 +656,19 @@ export function diffPixels(after: Uint8ClampedArray, before: Uint8ClampedArray,}return n ? changed / n : 0;}++/** Where the gallery preview stands in `ids`: on the image it shows (`id`) wherever the list+ * moved it, else at its last position `at` (clamped); null when the list is empty. */+export function previewIndex(ids: string[], id: string, at: number): number | null {+ if (!ids.length) return null;+ const i = ids.indexOf(id);+ return i >= 0 ? i : Math.min(Math.max(at, 0), ids.length - 1);+}++/** The image to show once `id` leaves the list: the next one, the previous at the end, or+ * null when it was the only one (or not in the list). */+export function neighbourAfterRemoval(ids: string[], id: string): string | null {+ const i = ids.indexOf(id);+ if (i < 0) return null;+ return ids[i + 1] ?? ids[i - 1] ?? null;+}diff --git a/src/styles.css b/src/styles.cssindex eec62d9..7a3807b 100644--- a/src/styles.css+++ b/src/styles.css@@ -419,6 +419,23 @@ pre.diag { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font.viewer-tag { color: #fff; font-weight: 600; }.viewer-close { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: rgba(255, 255, 255, 0.12); }.viewer-close:hover { background: rgba(255, 255, 255, 0.22); }+/* previous / next on the sides of a picture; shown while the mouse moves */+.nav-arrow { position: absolute; top: 50%; z-index: 3; width: 48px; height: 48px; margin-top: -24px; border-radius: 999px; display: grid; place-items: center; color: #fff; background: rgba(0, 0, 0, 0.5); transition: opacity 0.2s, background 0.15s; }+.nav-arrow.left { left: 14px; }+.nav-arrow.right { right: 14px; }+.nav-arrow:hover { background: rgba(0, 0, 0, 0.72); }+.nav-arrow.hidden { opacity: 0; }+.nav-arrow:focus-visible { opacity: 1; }++/* gallery preview: one image over the grid */+.preview { position: absolute; inset: 0; z-index: 5; background: var(--bg); display: flex; flex-direction: column; }+.preview-prompt { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }+.preview-pos { font-size: 13px; font-variant-numeric: tabular-nums; }+.preview-stage { position: relative; flex: 1; min-height: 0; }+.preview-img { position: absolute; top: 0; bottom: 0; left: 76px; width: calc(100% - 152px); height: 100%; object-fit: contain; user-select: none; }+.preview-bar { display: flex; align-items: center; gap: 6px; padding: 10px 16px 14px; flex: none; }+.preview-bar .spacer { flex: 1; }+.preview-bar .btn.primary { margin-left: 6px; }/* ---------- aspect ratio and size menus ---------- */.popover.wide { min-width: 0; }