feat(ui): reset canvas layers only resets the layers

This commit is contained in:
psychedelicious 2025-01-03 16:25:43 +10:00 committed by Kent Keirsey
parent 157b92e0fd
commit ad0aa0e6b2
2 changed files with 15 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import {
useNewCanvasSession,
useNewGallerySession,
} from 'features/controlLayers/components/NewSessionConfirmationAlertDialog';
import { canvasReset } from 'features/controlLayers/store/actions';
import { allEntitiesDeleted } from 'features/controlLayers/store/canvasSlice';
import { paramsReset } from 'features/controlLayers/store/paramsSlice';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
@ -16,7 +16,7 @@ export const SessionMenuItems = memo(() => {
const { newGallerySessionWithDialog } = useNewGallerySession();
const { newCanvasSessionWithDialog } = useNewCanvasSession();
const resetCanvasLayers = useCallback(() => {
dispatch(canvasReset());
dispatch(allEntitiesDeleted());
}, [dispatch]);
const resetGenerationSettings = useCallback(() => {
dispatch(paramsReset());

View File

@ -80,6 +80,9 @@ import {
initialT2IAdapter,
} from './util';
/**
* Gets a fresh canvas initial state with no references in memory to existing objects.
*/
const getInitialState = (): CanvasState => {
const initialInpaintMaskState = getInpaintMaskState(getPrefixedId('inpaint_mask'));
const initialState: CanvasState = {
@ -1497,6 +1500,15 @@ export const canvasSlice = createSlice({
break;
}
},
allEntitiesDeleted: (state) => {
// Deleting all entities is equivalent to resetting the state for each entity type
const initialState = getInitialState();
state.rasterLayers = initialState.rasterLayers;
state.controlLayers = initialState.controlLayers;
state.inpaintMasks = initialState.inpaintMasks;
state.regionalGuidance = initialState.regionalGuidance;
state.referenceImages = initialState.referenceImages;
},
canvasMetadataRecalled: (state, action: PayloadAction<CanvasMetadata>) => {
const { controlLayers, inpaintMasks, rasterLayers, referenceImages, regionalGuidance } = action.payload;
state.controlLayers.entities = controlLayers;
@ -1593,7 +1605,7 @@ export const {
entityArrangedToBack,
entityOpacityChanged,
entitiesReordered,
// allEntitiesDeleted, // currently unused
allEntitiesDeleted,
allEntitiesOfTypeIsHiddenToggled,
// bbox
bboxChangedFromCanvas,