Browse Source

Have CodeEditor.Model take options as object

Vidar Tonaas Fauske 8 năm trước cách đây
mục cha
commit
c2bb7ac0f2
3 tập tin đã thay đổi với 33 bổ sung7 xóa
  1. 22 4
      src/codeeditor/editor.ts
  2. 2 2
      src/codemirror/factory.ts
  3. 9 1
      test/src/codeeditor/editor.spec.ts

+ 22 - 4
src/codeeditor/editor.ts

@@ -198,10 +198,12 @@ namespace CodeEditor {
   export
   class Model implements IModel {
     /**
-     * Construct a new Model
+     * Construct a new Model.
      */
-    constructor(value?: string) {
-      this._value = new ObservableString(value);
+    constructor(options?: Model.IOptions) {
+      options = options || {};
+      this._value = new ObservableString(options.value);
+      this._mimetype = options.mimeType || 'text/plain';
     }
 
     /**
@@ -264,7 +266,7 @@ namespace CodeEditor {
 
     private _value: ObservableString;
     private _selections = new ObservableMap<ITextSelection[]>();
-    private _mimetype = 'text/plain';
+    private _mimetype: string;
     private _isDisposed = false;
   }
 
@@ -554,4 +556,20 @@ namespace CodeEditor {
     */
     selectionStyle?: CodeEditor.ISelectionStyle;
   }
+
+  export
+  namespace Model {
+    export
+    interface IOptions {
+      /**
+       * The initial value of the model.
+       */
+      value?: string;
+
+      /**
+       * The mimetype of the model.
+       */
+      mimeType?: string;
+    }
+  }
 }

+ 2 - 2
src/codemirror/factory.ts

@@ -20,7 +20,7 @@ export
 class CodeMirrorEditorFactory implements IEditorFactoryService {
 
   /**
-   * Construct an IEditorFactoryService for CodeMirrorEditors
+   * Construct an IEditorFactoryService for CodeMirrorEditors.
    */
   constructor(codeMirrorOptions?: CodeMirror.EditorConfiguration) {
     this.inlineCodeMirrorOptions = {
@@ -73,7 +73,7 @@ class CodeMirrorEditorFactory implements IEditorFactoryService {
 
 
 namespace Private {
-  // Replace with Object.assign when available
+  // Replace with Object.assign when available.
   export
   function assign<T>(target: T, ...configs: any[]): T {
     for (const source of configs) {

+ 9 - 1
test/src/codeeditor/editor.spec.ts

@@ -27,12 +27,20 @@ describe('CodeEditor.Model', () => {
     });
 
     it('should create a CodeEditor Model with an initial value', () => {
-      let other = new CodeEditor.Model('Initial text here');
+      let other = new CodeEditor.Model({value: 'Initial text here'});
       expect(other).to.be.a(CodeEditor.Model);
       expect(other.value.text).to.equal('Initial text here');
       other.dispose();
     });
 
+    it('should create a CodeEditor Model with an initial mimetype', () => {
+      let other = new CodeEditor.Model({value: 'import this', mimeType: 'text/x-python'});
+      expect(other).to.be.a(CodeEditor.Model);
+      expect(other.mimeType).to.equal('text/x-python');
+      expect(other.value.text).to.equal('import this');
+      other.dispose();
+    });
+
   });
 
   describe('#mimeTypeChanged', () => {