Permalink
Browse files

Merge pull request #12865 from adobe/zaggino/undo-history-lineendings

undo history not working, when line-endings change after save
  • Loading branch information...
2 parents c90da3a + 3421539 commit 3af64fae4b8430318770375c0125fcc9eeda1e85 @swmitra swmitra committed on GitHub Nov 1, 2016
Showing with 29 additions and 1 deletion.
  1. +5 −1 src/editor/Editor.js
  2. +24 −0 test/spec/Document-test.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;
}
@@ -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 () {

0 comments on commit 3af64fa

Please sign in to comment.