浏览代码

Save using CRLF line endings if a text file was loaded containing them.

Ian Rose 6 年之前
父节点
当前提交
1f7f6d3166
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      packages/docregistry/src/context.ts

+ 8 - 2
packages/docregistry/src/context.ts

@@ -471,6 +471,9 @@ export class Context<T extends DocumentRegistry.IModel>
       content = model.toJSON();
     } else {
       content = model.toString();
+      if (this._useCRLF) {
+        content = content.replace(/\n/g, '\r\n');
+      }
     }
 
     let options = {
@@ -560,8 +563,10 @@ export class Context<T extends DocumentRegistry.IModel>
           // Convert line endings if necessary, marking the file
           // as dirty.
           if (content.indexOf('\r') !== -1) {
-            dirty = true;
-            content = content.replace(/\r\n|\r/g, '\n');
+            this._useCRLF = true;
+            content = content.replace(/\r\n/g, '\n');
+          } else {
+            this._useCRLF = false;
           }
           model.fromString(content);
           if (initializeModel) {
@@ -765,6 +770,7 @@ export class Context<T extends DocumentRegistry.IModel>
   private _model: T;
   private _modelDB: IModelDB;
   private _path = '';
+  private _useCRLF = false;
   private _factory: DocumentRegistry.IModelFactory<T>;
   private _contentsModel: Contents.IModel | null = null;
   private _readyPromise: Promise<void>;