File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
invokeai/frontend/web/src/features/controlLayers/components/StagingArea Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments