From 5826c7f39d62716c69820be7746aff70be89cfae Mon Sep 17 00:00:00 2001 From: "Sparrow.jang" Date: Wed, 20 Dec 2017 23:10:17 +0800 Subject: [PATCH 1/3] Fixed an error that stop unshift when position less than max length --- lib/simple-undo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simple-undo.js b/lib/simple-undo.js index 81d7f51..f721609 100644 --- a/lib/simple-undo.js +++ b/lib/simple-undo.js @@ -51,7 +51,7 @@ SimpleUndo.prototype.clear = function() { SimpleUndo.prototype.save = function() { this.provider(function(current) { - truncate(this.stack, this.maxLength); + if (this.position >= this.maxLength) truncate(this.stack, this.maxLength); this.position = Math.min(this.position,this.stack.length - 1); this.stack = this.stack.slice(0, this.position + 1); From a39d104fdf051cb0d424927c739508dce6c10bc5 Mon Sep 17 00:00:00 2001 From: "Sparrow.jang" Date: Wed, 20 Dec 2017 23:13:06 +0800 Subject: [PATCH 2/3] Release 1.0.2 version --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 863a2fa..e6de093 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "simple-undo", - "version": "1.0.1", + "version": "1.0.2", "authors": [ "Matthias Jouan " ], diff --git a/package.json b/package.json index 3a6ef95..69931e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-undo", - "version": "1.0.1", + "version": "1.0.2", "description": "a very basic javascript undo/redo stack for managing histories of basically anything", "main": "./lib/simple-undo.js", "scripts": { From 735755eff6b97a99ec30ed995a436a9b015f434d Mon Sep 17 00:00:00 2001 From: "Sparrow.jang" Date: Thu, 21 Dec 2017 12:56:41 +0800 Subject: [PATCH 3/3] Add a test case for https://github.com/mattjmattj/simple-undo/pull/3 --- tests/simple-undo.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/simple-undo.js b/tests/simple-undo.js index a892b6f..825503d 100644 --- a/tests/simple-undo.js +++ b/tests/simple-undo.js @@ -151,4 +151,31 @@ describe('SimpleUndo', function() { }); }); -}) \ No newline at end of file + + it('should reserve initial when undo position to be 0 and save', function() { + var count = 0; + var provider = function(done) { + done(count++); + } + + var history = new SimpleUndo({ + provider: provider, + maxLength: 3 + }); + + history.initialize('initial'); + history.save(); + history.save(); + history.save(); + history.undo(); + history.undo(); + history.undo(); + + history.canUndo().should.be.false; + history.count().should.equal(3); + history.save(); + history.stack.length.should.equal(2); + history.stack[0].should.equal('initial'); + history.stack[1].should.equal(3); + }); +})