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

Commit

Permalink
Merge pull request #12865 from adobe/zaggino/undo-history-lineendings
Browse files Browse the repository at this point in the history
undo history not working, when line-endings change after save
  • Loading branch information
swmitra authored Nov 1, 2016
2 parents c90da3a + 3421539 commit 3af64fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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

0 comments on commit 3af64fa

Please sign in to comment.