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): the right-click acts on the selection as it stands, not as last drawn (D3, Mac run)

purple32fd78b4a818
diff --git a/src/components/create/experimental/CreatePanel.tsx b/src/components/create/experimental/CreatePanel.tsx
index a939a570..6fd89ece 100644
--- a/src/components/create/experimental/CreatePanel.tsx
+++ b/src/components/create/experimental/CreatePanel.tsx
@@ -44,7 +44,7 @@ export function CreatePanel({ open, onOpenChange, activeId, onSelect }: Props) {
// Several at once (D3, 3.0.9): Cmd/Ctrl-click, Shift range, Cmd/Ctrl+A,
// Escape. The menu and the bar act on `sel.ids` with the tile's own code.
const [stored, setSel] = useState<GallerySelection>(EMPTY_SELECTION)
- const [menu, setMenu] = useState<{ x: number; y: number; ids: readonly string[] } | null>(null)
+ const [menu, setMenu] = useState<{ x: number; y: number } | null>(null)
const [confirming, setConfirming] = useState<readonly string[]>([])
const order = gallery.map((g) => g.id)
// Items no longer shown (another folder, deleted) are not selected.
@@ -61,9 +61,9 @@ export function CreatePanel({ open, onOpenChange, activeId, onSelect }: Props) {
}
const onTileMenu = (e: ReactMouseEvent, id: string) => {
e.preventDefault()
- const next = menuSelection(sel, id)
- setSel(next)
- setMenu({ x: e.clientX, y: e.clientY, ids: next.ids })
+ // From the state too; the menu acts on whatever is selected when it shows.
+ setSel((prev) => menuSelection(keepShown(prev, order), id))
+ setMenu({ x: e.clientX, y: e.clientY })
}
const onGridKey = (e: React.KeyboardEvent) => {
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'a' && order.length > 0) {
@@ -181,12 +181,12 @@ export function CreatePanel({ open, onOpenChange, activeId, onSelect }: Props) {
</div>
</Modal>
</OnBody>
- {menu && (
+ {menu && selecting && (
<ContextMenu
- items={buildGalleryMenu(actionsFor(menu.ids), menu.ids.length)}
+ items={buildGalleryMenu(actionsFor(sel.ids), sel.ids.length)}
x={menu.x}
y={menu.y}
- label={menu.ids.length > 1 ? `Actions for ${menu.ids.length} items` : 'Actions for this item'}
+ label={sel.ids.length > 1 ? `Actions for ${sel.ids.length} items` : 'Actions for this item'}
onClose={() => setMenu(null)}
/>
)}
diff --git a/src/components/create/experimental/__tests__/galerie-mehrfachauswahl.test.tsx b/src/components/create/experimental/__tests__/galerie-mehrfachauswahl.test.tsx
index 8481e7a5..78109202 100644
--- a/src/components/create/experimental/__tests__/galerie-mehrfachauswahl.test.tsx
+++ b/src/components/create/experimental/__tests__/galerie-mehrfachauswahl.test.tsx
@@ -117,6 +117,18 @@ describe('the right-click menu', () => {
expect(within(menu).getAllByRole('menuitem').map((m) => m.textContent)).toEqual(['Move 2 to folder…', 'Download 2', 'Delete 2…'])
})
+ it('a right-click right after Cmd-clicks, before the next render, keeps them (Mac run)', () => {
+ panel()
+ const fire = (id: string, type: string, init: MouseEventInit) =>
+ tile(id).dispatchEvent(new MouseEvent(type, { bubbles: true, cancelable: true, ...init }))
+ act(() => {
+ fire('a', 'click', { metaKey: true })
+ fire('b', 'click', { metaKey: true })
+ fire('b', 'contextmenu', { clientX: 40, clientY: 40 })
+ })
+ expect(within(screen.getByRole('menu')).getAllByRole('menuitem').map((m) => m.textContent)).toEqual(['Move 2 to folder…', 'Download 2', 'Delete 2…'])
+ })
+
it('on an unselected tile acts on that tile alone', () => {
panel()
fireEvent.click(tile('a'), { metaKey: true })