Fixed undo not working correctly after first undo
This commit is contained in:
parent
b431839bce
commit
3229487cf0
1 changed files with 17 additions and 19 deletions
|
|
@ -52,25 +52,23 @@ export function UndoRedoProvider({ children }) {
|
||||||
|
|
||||||
const takeSnapshot = useCallback(() => {
|
const takeSnapshot = useCallback(() => {
|
||||||
// push the current graph to the past state
|
// push the current graph to the past state
|
||||||
setPast((old) => {
|
let newPast = cloneDeep(past);
|
||||||
let newPast = cloneDeep(old);
|
|
||||||
let newState = {
|
let newState = {
|
||||||
nodes: cloneDeep(getNodes()),
|
nodes: cloneDeep(getNodes()),
|
||||||
edges: cloneDeep(getEdges()),
|
edges: cloneDeep(getEdges()),
|
||||||
};
|
};
|
||||||
if (
|
if (
|
||||||
old[tabIndex] &&
|
past[tabIndex] &&
|
||||||
JSON.stringify(old[tabIndex][old[tabIndex].length - 1]) !==
|
JSON.stringify(past[tabIndex][past[tabIndex].length - 1]) !==
|
||||||
JSON.stringify(newState)
|
JSON.stringify(newState)
|
||||||
) {
|
) {
|
||||||
newPast[tabIndex] = old[tabIndex].slice(
|
newPast[tabIndex] = past[tabIndex].slice(
|
||||||
old[tabIndex].length - defaultOptions.maxHistorySize + 1,
|
past[tabIndex].length - defaultOptions.maxHistorySize + 1,
|
||||||
old[tabIndex].length
|
past[tabIndex].length
|
||||||
);
|
);
|
||||||
newPast[tabIndex].push(newState);
|
newPast[tabIndex].push(newState);
|
||||||
}
|
}
|
||||||
return newPast;
|
setPast(newPast);
|
||||||
});
|
|
||||||
|
|
||||||
// whenever we take a new snapshot, the redo operations need to be cleared to avoid state mismatches
|
// whenever we take a new snapshot, the redo operations need to be cleared to avoid state mismatches
|
||||||
setFuture((old) => {
|
setFuture((old) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue