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

undo history not working, when line-endings change after save #12865

Merged
merged 3 commits into from
Nov 1, 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: 5 additions & 1 deletion src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,11 @@ define(function (require, exports, module) {
*/
Editor.prototype._resetText = function (text) {
var currentText = this._codeMirror.getValue();
if (text === currentText) {

// compare with ignoring line-endings, issue #11826
var textLF = text ? text.replace(/(\r\n|\r|\n)/g, "\n") : null;
var currentTextLF = currentText ? currentText.replace(/(\r\n|\r|\n)/g, "\n") : null;
if (textLF === currentTextLF) {
// there's nothing to reset
return;
}
Expand Down
24 changes: 24 additions & 0 deletions test/spec/Document-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,30 @@ define(function (require, exports, module) {
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1);
});
});

it("should not clean history when reset is called with the same text with different line-endings", function () {
runs(function () {
promise = CommandManager.execute(Commands.FILE_OPEN, {fullPath: JS_FILE});
waitsForDone(promise, "Open file");
});
runs(function () {
var doc = DocumentManager.getOpenDocumentForPath(JS_FILE);
var crlf = "a\r\nb\r\nc";
var lf = "a\nb\nc";

// Put some text into editor
doc.setText(crlf);
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1);

// Reset text with the same value, expect history not to change
doc.refreshText(lf, Date.now());
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1);

// Reset text with the same value, expect history not to change
doc.refreshText(crlf, Date.now());
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1);
});
});
});

describe("Refresh and change events", function () {
Expand Down