From 44657efe7187a579ee8d7a7e0d1ddaf001fbf02f Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sat, 11 Jan 2020 20:45:56 -0800 Subject: [PATCH] Fix undoOnce (#332) I just pasted @enzoferey's implementation and it fixed the bug reported by @dwelle Fixes #307 --- src/history.ts | 16 ++++++++-------- src/index.tsx | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/history.ts b/src/history.ts index 4fc44445..24fee16e 100644 --- a/src/history.ts +++ b/src/history.ts @@ -51,15 +51,15 @@ class SceneHistory { return null; } - undoOnce(elements: readonly ExcalidrawElement[]) { - const currentEntry = this.generateCurrentEntry(elements); - let entryToRestore = this.stateHistory.pop(); - - // If nothing was changed since last, take the previous one - if (currentEntry === entryToRestore) { - entryToRestore = this.stateHistory.pop(); + undoOnce() { + if (this.stateHistory.length === 0) { + return null; } - if (entryToRestore !== undefined) { + + const currentEntry = this.stateHistory.pop(); + const entryToRestore = this.stateHistory[this.stateHistory.length - 1]; + + if (currentEntry !== undefined) { this.redoStack.push(currentEntry); return this.restoreEntry(entryToRestore); } diff --git a/src/index.tsx b/src/index.tsx index 1615b1f7..7b8f06a3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -256,7 +256,7 @@ export class App extends React.Component<{}, AppState> { } } else { // undo action - const data = history.undoOnce(elements); + const data = history.undoOnce(); if (data !== null) { elements = data; }