From 23511d68dbd8b29dba8e603a11bd7b3663550e37 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 5 Jun 2025 20:03:26 +1000 Subject: [PATCH] feat(ui): when discarding last item, select new last instead of first --- .../controlLayers/components/SimpleSession/context.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/invokeai/frontend/web/src/features/controlLayers/components/SimpleSession/context.tsx b/invokeai/frontend/web/src/features/controlLayers/components/SimpleSession/context.tsx index 5f1c73fdb0..33b5fc9cc1 100644 --- a/invokeai/frontend/web/src/features/controlLayers/components/SimpleSession/context.tsx +++ b/invokeai/frontend/web/src/features/controlLayers/components/SimpleSession/context.tsx @@ -344,7 +344,10 @@ export const CanvasSessionContextProvider = memo( // If an item is selected and it is not in the list of items, un-set it. This effect will run again and we'll // the above case, selecting the first item if there are any. if (selectedItemId !== null && items.findIndex(({ item_id }) => item_id === selectedItemId) === -1) { - const prevIndex = $prevItems.get().findIndex(({ item_id }) => item_id === selectedItemId); + let prevIndex = $prevItems.get().findIndex(({ item_id }) => item_id === selectedItemId); + if (prevIndex >= items.length) { + prevIndex = items.length - 1; + } const nextItem = items[prevIndex]; $selectedItemId.set(nextItem?.item_id ?? null); return;