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

Commit 86c037f

Browse files
zagginonethip
authored andcommitted
do nothing when trying to reset with the same content which is already present (#12681)
* do nothing when trying to reset with the same content which is already present * add test
1 parent 424d808 commit 86c037f

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/editor/Editor.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,12 @@ define(function (require, exports, module) {
10471047
* @param {!string} text
10481048
*/
10491049
Editor.prototype._resetText = function (text) {
1050+
var currentText = this._codeMirror.getValue();
1051+
if (text === currentText) {
1052+
// there's nothing to reset
1053+
return;
1054+
}
1055+
10501056
var perfTimerName = PerfUtils.markStart("Editor._resetText()\t" + (!this.document || this.document.file.fullPath));
10511057

10521058
var cursorPos = this.getCursorPos(),

test/spec/Document-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,24 @@ define(function (require, exports, module) {
400400
doc = null;
401401
});
402402
});
403+
404+
it("should not clean history when reset is called with the same text as in the editor", function () {
405+
runs(function () {
406+
promise = CommandManager.execute(Commands.FILE_OPEN, {fullPath: JS_FILE});
407+
waitsForDone(promise, "Open file");
408+
});
409+
runs(function () {
410+
var doc = DocumentManager.getOpenDocumentForPath(JS_FILE);
411+
412+
// Put some text into editor
413+
doc.setText("Foo");
414+
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1);
415+
416+
// Reset text with the same value, expect history not to change
417+
doc.refreshText("Foo", Date.now());
418+
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1);
419+
});
420+
});
403421
});
404422

405423
describe("Refresh and change events", function () {

0 commit comments

Comments
 (0)