mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Limits history to 256 for each of undo and redo
This commit is contained in:
parent
f82e82f1bb
commit
88d02585e7
@ -46,6 +46,7 @@ export interface GenericCanvasState {
|
|||||||
isMoveStageKeyHeld: boolean;
|
isMoveStageKeyHeld: boolean;
|
||||||
intermediateImage?: InvokeAI.Image;
|
intermediateImage?: InvokeAI.Image;
|
||||||
shouldShowIntermediates: boolean;
|
shouldShowIntermediates: boolean;
|
||||||
|
maxHistory: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CanvasLayer = 'base' | 'mask';
|
export type CanvasLayer = 'base' | 'mask';
|
||||||
@ -163,6 +164,7 @@ const initialGenericCanvasState: GenericCanvasState = {
|
|||||||
isMoveStageKeyHeld: false,
|
isMoveStageKeyHeld: false,
|
||||||
shouldShowIntermediates: true,
|
shouldShowIntermediates: true,
|
||||||
isMovingStage: false,
|
isMovingStage: false,
|
||||||
|
maxHistory: 256,
|
||||||
};
|
};
|
||||||
|
|
||||||
const initialCanvasState: CanvasState = {
|
const initialCanvasState: CanvasState = {
|
||||||
@ -530,14 +532,21 @@ export const canvasSlice = createSlice({
|
|||||||
}>
|
}>
|
||||||
) => {
|
) => {
|
||||||
const { boundingBox, image } = action.payload;
|
const { boundingBox, image } = action.payload;
|
||||||
|
|
||||||
if (!boundingBox || !image) return;
|
if (!boundingBox || !image) return;
|
||||||
|
|
||||||
const { x, y } = boundingBox;
|
const { x, y } = boundingBox;
|
||||||
|
const currentCanvas = state.outpainting;
|
||||||
|
|
||||||
state.outpainting.pastObjects.push([...state.outpainting.objects]);
|
currentCanvas.pastObjects.push([...currentCanvas.objects]);
|
||||||
state.outpainting.futureObjects = [];
|
|
||||||
|
|
||||||
state.outpainting.objects.push({
|
if (currentCanvas.pastObjects.length > currentCanvas.maxHistory) {
|
||||||
|
currentCanvas.pastObjects.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentCanvas.futureObjects = [];
|
||||||
|
|
||||||
|
currentCanvas.objects.push({
|
||||||
kind: 'image',
|
kind: 'image',
|
||||||
layer: 'base',
|
layer: 'base',
|
||||||
x,
|
x,
|
||||||
@ -560,6 +569,10 @@ export const canvasSlice = createSlice({
|
|||||||
|
|
||||||
currentCanvas.pastObjects.push(currentCanvas.objects);
|
currentCanvas.pastObjects.push(currentCanvas.objects);
|
||||||
|
|
||||||
|
if (currentCanvas.pastObjects.length > currentCanvas.maxHistory) {
|
||||||
|
currentCanvas.pastObjects.shift();
|
||||||
|
}
|
||||||
|
|
||||||
currentCanvas.objects.push({
|
currentCanvas.objects.push({
|
||||||
kind: 'line',
|
kind: 'line',
|
||||||
layer,
|
layer,
|
||||||
@ -580,23 +593,37 @@ export const canvasSlice = createSlice({
|
|||||||
lastLine.points.push(...action.payload);
|
lastLine.points.push(...action.payload);
|
||||||
},
|
},
|
||||||
undo: (state) => {
|
undo: (state) => {
|
||||||
if (state[state.currentCanvas].objects.length === 0) return;
|
const currentCanvas = state[state.currentCanvas];
|
||||||
|
if (currentCanvas.objects.length === 0) return;
|
||||||
|
|
||||||
|
const newObjects = currentCanvas.pastObjects.pop();
|
||||||
|
|
||||||
const newObjects = state[state.currentCanvas].pastObjects.pop();
|
|
||||||
if (!newObjects) return;
|
if (!newObjects) return;
|
||||||
state[state.currentCanvas].futureObjects.unshift(
|
|
||||||
state[state.currentCanvas].objects
|
currentCanvas.futureObjects.unshift(currentCanvas.objects);
|
||||||
);
|
|
||||||
state[state.currentCanvas].objects = newObjects;
|
if (currentCanvas.futureObjects.length > currentCanvas.maxHistory) {
|
||||||
|
currentCanvas.futureObjects.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentCanvas.objects = newObjects;
|
||||||
},
|
},
|
||||||
redo: (state) => {
|
redo: (state) => {
|
||||||
if (state[state.currentCanvas].futureObjects.length === 0) return;
|
const currentCanvas = state[state.currentCanvas];
|
||||||
const newObjects = state[state.currentCanvas].futureObjects.shift();
|
|
||||||
|
if (currentCanvas.futureObjects.length === 0) return;
|
||||||
|
|
||||||
|
const newObjects = currentCanvas.futureObjects.shift();
|
||||||
|
|
||||||
if (!newObjects) return;
|
if (!newObjects) return;
|
||||||
state[state.currentCanvas].pastObjects.push(
|
|
||||||
state[state.currentCanvas].objects
|
currentCanvas.pastObjects.push(currentCanvas.objects);
|
||||||
);
|
|
||||||
state[state.currentCanvas].objects = newObjects;
|
if (currentCanvas.pastObjects.length > currentCanvas.maxHistory) {
|
||||||
|
currentCanvas.pastObjects.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentCanvas.objects = newObjects;
|
||||||
},
|
},
|
||||||
setShouldShowGrid: (state, action: PayloadAction<boolean>) => {
|
setShouldShowGrid: (state, action: PayloadAction<boolean>) => {
|
||||||
state.outpainting.shouldShowGrid = action.payload;
|
state.outpainting.shouldShowGrid = action.payload;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user