Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

do nothing when trying to reset with the same content which is already present #12681

Merged
merged 2 commits into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
18 changes: 18 additions & 0 deletions test/spec/Document-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down