diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 869bee317ca..fab539ee189 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -1047,6 +1047,12 @@ define(function (require, exports, module) { * @param {!string} text */ Editor.prototype._resetText = function (text) { + var currentText = this._codeMirror.getValue(); + if (text === currentText) { + // there's nothing to reset + return; + } + var perfTimerName = PerfUtils.markStart("Editor._resetText()\t" + (!this.document || this.document.file.fullPath)); var cursorPos = this.getCursorPos(), diff --git a/test/spec/Document-test.js b/test/spec/Document-test.js index 935c22f36da..357cde4fbd9 100644 --- a/test/spec/Document-test.js +++ b/test/spec/Document-test.js @@ -400,6 +400,24 @@ define(function (require, exports, module) { doc = null; }); }); + + it("should not clean history when reset is called with the same text as in the editor", function () { + runs(function () { + promise = CommandManager.execute(Commands.FILE_OPEN, {fullPath: JS_FILE}); + waitsForDone(promise, "Open file"); + }); + runs(function () { + var doc = DocumentManager.getOpenDocumentForPath(JS_FILE); + + // Put some text into editor + doc.setText("Foo"); + expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1); + + // Reset text with the same value, expect history not to change + doc.refreshText("Foo", Date.now()); + expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1); + }); + }); }); describe("Refresh and change events", function () {