Skip to content

Commit 1c3be7e

Browse files
feat(ui): handle ref image deletion autoswitch
1 parent d0bb5a5 commit 1c3be7e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

invokeai/frontend/web/src/features/controlLayers/components/RefImage/RefImage.tsx

Whitespace-only changes.

invokeai/frontend/web/src/features/controlLayers/store/refImagesSlice.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getPrefixedId } from 'features/controlLayers/konva/util';
66
import { canvasMetadataRecalled } from 'features/controlLayers/store/canvasSlice';
77
import type { FLUXReduxImageInfluence, RefImagesState } from 'features/controlLayers/store/types';
88
import { zModelIdentifierField } from 'features/nodes/types/common';
9-
import { isEqual } from 'lodash-es';
9+
import { clamp, isEqual } from 'lodash-es';
1010
import type { ApiModelConfig, FLUXReduxModelConfig, ImageDTO, IPAdapterModelConfig } from 'services/api/types';
1111
import { assert } from 'tsafe';
1212
import type { PartialDeep } from 'type-fest';
@@ -188,10 +188,11 @@ export const refImagesSlice = createSlice({
188188
},
189189
refImageDeleted: (state, action: PayloadActionWithId) => {
190190
const { id } = action.payload;
191+
const currentIndex = state.entities.findIndex((rg) => rg.id === id);
191192
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;
195196
},
196197
refImageSelected: (state, action: PayloadAction<{ id: string }>) => {
197198
const { id } = action.payload;
@@ -238,7 +239,7 @@ export const refImagesPersistConfig: PersistConfig<RefImagesState> = {
238239
name: refImagesSlice.name,
239240
initialState: getInitialRefImagesState(),
240241
migrate,
241-
persistDenylist: ['isPanelOpen'],
242+
persistDenylist: ['selectedEntityId', 'isPanelOpen'],
242243
};
243244

244245
export const selectRefImagesSlice = (state: RootState) => state.refImages;

0 commit comments

Comments
 (0)