From d09eb4c9f46010a9daf0c6eea4f9042f674d0a11 Mon Sep 17 00:00:00 2001 From: Martin Zagora Date: Tue, 1 Nov 2016 17:56:50 +1100 Subject: [PATCH 1/3] when reseting text in editor, ignore line-ending differences --- src/editor/Editor.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 99203dc8341..2bab93c1044 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -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; } From b0d085996106cfd9773ffb62c3d41d1ba3ba0bb1 Mon Sep 17 00:00:00 2001 From: Martin Zagora Date: Tue, 1 Nov 2016 21:03:21 +1100 Subject: [PATCH 2/3] add test --- test/spec/Document-test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/spec/Document-test.js b/test/spec/Document-test.js index 357cde4fbd9..7412ae645a9 100644 --- a/test/spec/Document-test.js +++ b/test/spec/Document-test.js @@ -418,6 +418,24 @@ 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); + + // Put some text into editor + doc.setText("a\r\nb\r\nc"); + expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1); + + // Reset text with the same value, expect history not to change + doc.refreshText("a\nb\nc", Date.now()); + expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1); + }); + }); }); describe("Refresh and change events", function () { From 342153965eb1140fdac6ca5e56f8570d01804900 Mon Sep 17 00:00:00 2001 From: Martin Zagora Date: Tue, 1 Nov 2016 21:07:52 +1100 Subject: [PATCH 3/3] fix test --- test/spec/Document-test.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/spec/Document-test.js b/test/spec/Document-test.js index 7412ae645a9..17514ec4db3 100644 --- a/test/spec/Document-test.js +++ b/test/spec/Document-test.js @@ -426,13 +426,19 @@ define(function (require, exports, module) { }); 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("a\r\nb\r\nc"); + doc.setText(crlf); expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1); // Reset text with the same value, expect history not to change - doc.refreshText("a\nb\nc", Date.now()); + 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); }); });