Skip to content

Commit 0b16bd4

Browse files
authored
Merge pull request #3 from eHanlin/master
Fixed an error about unshift stack
2 parents 10ad09a + 735755e commit 0b16bd4

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-undo",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"authors": [
55
"Matthias Jouan <matthias.jouan@gmail.com>"
66
],

lib/simple-undo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ SimpleUndo.prototype.clear = function() {
5151

5252
SimpleUndo.prototype.save = function() {
5353
this.provider(function(current) {
54-
truncate(this.stack, this.maxLength);
54+
if (this.position >= this.maxLength) truncate(this.stack, this.maxLength);
5555
this.position = Math.min(this.position,this.stack.length - 1);
5656

5757
this.stack = this.stack.slice(0, this.position + 1);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-undo",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "a very basic javascript undo/redo stack for managing histories of basically anything",
55
"main": "./lib/simple-undo.js",
66
"scripts": {

tests/simple-undo.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,31 @@ describe('SimpleUndo', function() {
151151
});
152152

153153
});
154-
})
154+
155+
it('should reserve initial when undo position to be 0 and save', function() {
156+
var count = 0;
157+
var provider = function(done) {
158+
done(count++);
159+
}
160+
161+
var history = new SimpleUndo({
162+
provider: provider,
163+
maxLength: 3
164+
});
165+
166+
history.initialize('initial');
167+
history.save();
168+
history.save();
169+
history.save();
170+
history.undo();
171+
history.undo();
172+
history.undo();
173+
174+
history.canUndo().should.be.false;
175+
history.count().should.equal(3);
176+
history.save();
177+
history.stack.length.should.equal(2);
178+
history.stack[0].should.equal('initial');
179+
history.stack[1].should.equal(3);
180+
});
181+
})

0 commit comments

Comments
 (0)