@@ -6,7 +6,7 @@ import { getPrefixedId } from 'features/controlLayers/konva/util';
6
6
import { canvasMetadataRecalled } from 'features/controlLayers/store/canvasSlice' ;
7
7
import type { FLUXReduxImageInfluence , RefImagesState } from 'features/controlLayers/store/types' ;
8
8
import { zModelIdentifierField } from 'features/nodes/types/common' ;
9
- import { isEqual } from 'lodash-es' ;
9
+ import { clamp , isEqual } from 'lodash-es' ;
10
10
import type { ApiModelConfig , FLUXReduxModelConfig , ImageDTO , IPAdapterModelConfig } from 'services/api/types' ;
11
11
import { assert } from 'tsafe' ;
12
12
import type { PartialDeep } from 'type-fest' ;
@@ -188,10 +188,11 @@ export const refImagesSlice = createSlice({
188
188
} ,
189
189
refImageDeleted : ( state , action : PayloadActionWithId ) => {
190
190
const { id } = action . payload ;
191
+ const currentIndex = state . entities . findIndex ( ( rg ) => rg . id === id ) ;
191
192
state . entities = state . entities . filter ( ( rg ) => rg . id !== id ) ;
192
- if ( state . selectedEntityId === id ) {
193
- state . selectedEntityId = null ;
194
- }
193
+ const nextIndex = clamp ( currentIndex , 0 , state . entities . length - 1 ) ;
194
+ const nextEntity = state . entities [ nextIndex ] ;
195
+ state . selectedEntityId = nextEntity ?. id ?? null ;
195
196
} ,
196
197
refImageSelected : ( state , action : PayloadAction < { id : string } > ) => {
197
198
const { id } = action . payload ;
@@ -238,7 +239,7 @@ export const refImagesPersistConfig: PersistConfig<RefImagesState> = {
238
239
name : refImagesSlice . name ,
239
240
initialState : getInitialRefImagesState ( ) ,
240
241
migrate,
241
- persistDenylist : [ 'isPanelOpen' ] ,
242
+ persistDenylist : [ 'selectedEntityId' , ' isPanelOpen'] ,
242
243
} ;
243
244
244
245
export const selectRefImagesSlice = ( state : RootState ) => state . refImages ;
0 commit comments