From 7d4fb250cdb7cc0472c6fb2863ab35a4fc833edf Mon Sep 17 00:00:00 2001 From: Misode Date: Fri, 13 Sep 2019 14:59:30 +0200 Subject: [PATCH] Fix problems with historyBuffer --- model.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/model.js b/model.js index ed83f47b..ccf494f7 100644 --- a/model.js +++ b/model.js @@ -63,18 +63,16 @@ function redo() { function invalidated() { if (historyIndex === history.length - 1) { - historyIndex += 1; history.push(JSON.stringify(table)); + if (history.length > historyBuffer) { + history = history.slice(-historyBuffer); + } + historyIndex = history.length - 1; } else { historyIndex += 1; history = history.slice(0, historyIndex); history.push(JSON.stringify(table)); } - if (history.length > historyBuffer) { - console.log('remove history'); - historyIndex -= 1; - history.splice(0, 1); - } updateView(); }