Skip to content

Commit c5992ec

Browse files
fix(ui): better logic in staging area when canceling the selected item
1 parent 12a6239 commit c5992ec

File tree

1 file changed

+21
-0
lines changed
  • invokeai/frontend/web/src/features/controlLayers/components/StagingArea

1 file changed

+21
-0
lines changed

invokeai/frontend/web/src/features/controlLayers/components/StagingArea/state.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,27 @@ export class StagingAreaApi {
361361
}
362362
}
363363

364+
const selectedItemId = this.$selectedItemId.get();
365+
if (selectedItemId !== null && !items.find(({ item_id }) => item_id === selectedItemId)) {
366+
// If the selected item no longer exists, select the next best item.
367+
// Prefer the next item in the list - must check oldItems to determine this
368+
const nextItemIndex = oldItems.findIndex(({ item_id }) => item_id === selectedItemId);
369+
if (nextItemIndex !== -1) {
370+
const nextItem = items[nextItemIndex] ?? items[nextItemIndex - 1];
371+
if (nextItem) {
372+
this.$selectedItemId.set(nextItem.item_id);
373+
}
374+
} else {
375+
// Next, if there is an in-progress item, select that.
376+
const inProgressItem = items.find(({ status }) => status === 'in_progress');
377+
if (inProgressItem) {
378+
this.$selectedItemId.set(inProgressItem.item_id);
379+
}
380+
// Finally just select the first item.
381+
this.$selectedItemId.set(items[0]?.item_id ?? null);
382+
}
383+
}
384+
364385
this.$items.set(items);
365386
};
366387

0 commit comments

Comments
 (0)