From d27d92325d0883d17123fe1111f2de750a22ddd0 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 20 Nov 2022 19:59:06 +1100 Subject: [PATCH] Fixes bug where discarding staged images results in loss of history --- frontend/src/features/canvas/store/canvasSlice.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/features/canvas/store/canvasSlice.ts b/frontend/src/features/canvas/store/canvasSlice.ts index 879539265e..0e0576c1c0 100644 --- a/frontend/src/features/canvas/store/canvasSlice.ts +++ b/frontend/src/features/canvas/store/canvasSlice.ts @@ -328,9 +328,17 @@ export const canvasSlice = createSlice({ state.futureLayerStates = []; }, discardStagedImages: (state) => { + state.pastLayerStates.push(_.cloneDeep(state.layerState)); + + if (state.pastLayerStates.length > state.maxHistory) { + state.pastLayerStates.shift(); + } + state.layerState.stagingArea = { ...initialLayerState.stagingArea, }; + + state.futureLayerStates = []; state.shouldShowStagingOutline = true; }, addLine: (state, action: PayloadAction) => {