From 68a6a14d909f58e84b58199f6c8a267f49883a21 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 3 May 2015 14:55:08 +0400 Subject: [PATCH] fix clearUndo --- plugins/c9.ide.editors/undomanager.js | 15 +++++++-------- plugins/c9.ide.editors/undomanager_test.js | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/c9.ide.editors/undomanager.js b/plugins/c9.ide.editors/undomanager.js index 6ab1adc9..6560de05 100644 --- a/plugins/c9.ide.editors/undomanager.js +++ b/plugins/c9.ide.editors/undomanager.js @@ -10,7 +10,7 @@ define(function(require, module, exports) { var plugin = new Plugin("Ajax.org", main.consumes); var emit = plugin.getEmitter(); - var position = -1, mark = null, stack = []; + var position = -1, mark = -2, stack = []; if (options) setState(options); @@ -55,7 +55,7 @@ define(function(require, module, exports) { position = 0; if (mark < position) - mark = -1; + mark = -2; emit("change"); } @@ -64,7 +64,7 @@ define(function(require, module, exports) { stack = stack.slice(0, position + 1); if (mark > position) - mark = -1; + mark = -2; if (!noEvent) emit("change"); @@ -91,7 +91,7 @@ define(function(require, module, exports) { position--; if (mark == idx) - mark = -1; + mark = -2; else if (mark > idx) mark--; @@ -105,8 +105,7 @@ define(function(require, module, exports) { } function isAtBookmark(){ - return mark !== null && mark == position - || mark === null && position == -1; + return mark == position; } function item(idx) { @@ -133,7 +132,7 @@ define(function(require, module, exports) { return; // guard against broken stack stack = state.stack; - emit("change"); //If you remove this again, change the test + emit("change"); // If you remove this again, change the test } function findItem(compressedItem) { @@ -146,7 +145,7 @@ define(function(require, module, exports) { position = -1; stack = []; - mark = null; + mark = -1; emit("change"); } diff --git a/plugins/c9.ide.editors/undomanager_test.js b/plugins/c9.ide.editors/undomanager_test.js index b7624924..a3c57ada 100644 --- a/plugins/c9.ide.editors/undomanager_test.js +++ b/plugins/c9.ide.editors/undomanager_test.js @@ -133,7 +133,7 @@ require(["lib/architect/architect", "lib/chai/chai"], function (architect, chai) expect(undo.position).to.equal(4); undo.undo(); check++; - undo.setState({ position : -1, stack : stack, mark : null }); check++; + undo.setState({ position : -1, stack : stack, mark : -1 }); check++; expect(undo.isAtBookmark()).to.equal(true); expect(data).to.deep.equal(["a", "q"]); checkCount();