Encapsulate clearing redo stack within History

This commit is contained in:
Gasim Gasimzada 2020-01-06 21:41:23 +04:00
parent 9eeb4b10af
commit 1c96a4169d
2 changed files with 5 additions and 2 deletions

View file

@ -34,6 +34,10 @@ class SceneHistory {
this.skipRecording(); this.skipRecording();
} }
clearRedoStack() {
this.redoStack.splice(0, this.redoStack.length);
}
redoOnce(elements: ExcalidrawElement[]) { redoOnce(elements: ExcalidrawElement[]) {
const currentEntry = this.generateCurrentEntry(elements); const currentEntry = this.generateCurrentEntry(elements);
const entryToRestore = this.redoStack.pop(); const entryToRestore = this.redoStack.pop();

View file

@ -203,7 +203,6 @@ class App extends React.Component<{}, AppState> {
} else if (shapesShortcutKeys.includes(event.key.toLowerCase())) { } else if (shapesShortcutKeys.includes(event.key.toLowerCase())) {
this.setState({ elementType: findShapeByKey(event.key) }); this.setState({ elementType: findShapeByKey(event.key) });
} else if (event.metaKey && event.code === "KeyZ") { } else if (event.metaKey && event.code === "KeyZ") {
const currentEntry = history.generateCurrentEntry(elements);
if (event.shiftKey) { if (event.shiftKey) {
// Redo action // Redo action
history.redoOnce(elements); history.redoOnce(elements);
@ -914,7 +913,7 @@ class App extends React.Component<{}, AppState> {
saveToLocalStorage(elements, this.state); saveToLocalStorage(elements, this.state);
if (history.isRecording()) { if (history.isRecording()) {
history.pushEntry(history.generateCurrentEntry(elements)); history.pushEntry(history.generateCurrentEntry(elements));
history.redoStack.splice(0, history.redoStack.length); history.clearRedoStack();
} }
history.resumeRecording(); history.resumeRecording();
} }