瀏覽代碼

Finish codeeditor and codemirror changes

Steven Silvester 8 年之前
父節點
當前提交
d8aefbed87
共有 4 個文件被更改,包括 19 次插入12 次删除
  1. 3 2
      src/codeeditor/editor.ts
  2. 13 8
      src/codemirror/editor.ts
  3. 3 1
      src/codemirror/factory.ts
  4. 0 1
      src/codemirror/index.ts

+ 3 - 2
src/codeeditor/editor.ts

@@ -401,8 +401,9 @@ namespace CodeEditor {
       clearSignalData(this);
     }
 
-    private _value: new ObservableString();
-    private _selections: new Selections();
+    private _value = new ObservableString();
+    private _selections = new Selections();
+    private _mimetype = 'text/plain';
     private _isDisposed = false;
   }
 

+ 13 - 8
src/codemirror/editor.ts

@@ -20,6 +20,10 @@ import {
   IChangedArgs
 } from '../common/interfaces';
 
+import {
+  IObservableString, ObservableString
+} from '../common/observablestring';
+
 import {
   loadModeByMIME
 } from './';
@@ -28,10 +32,6 @@ import {
   CodeEditor
 } from '../codeeditor';
 
-import {
-  CodeMirrorModel
-} from './model';
-
 
 /**
  * The class name added to CodeMirrorWidget instances.
@@ -490,7 +490,7 @@ class CodeMirrorEditor implements CodeEditor.IEditor {
    */
   private _onValueChanged(value: IObservableString, args: ObservableString.IChangedArgs): void {
     this._changeGuard = true;
-    let doc = self._editor.getDoc();
+    let doc = this._editor.getDoc();
     switch (args.type) {
     case 'insert':
       let pos = doc.posFromIndex(args.start);
@@ -535,7 +535,7 @@ class CodeMirrorEditor implements CodeEditor.IEditor {
     this._changeGuard = false;
   }
 
-  private _model: CodeMirrorModel;
+  private _model: CodeEditor.IModel;
   private _editor: CodeMirror.Editor;
   private _isDisposed = false;
   protected selectionMarkers: { [key: string]: CodeMirror.TextMarker[] | undefined } = {};
@@ -553,14 +553,19 @@ namespace CodeMirrorEditor {
    */
   export
   interface IOptions extends CodeMirror.EditorConfiguration {
+    /**
+     * The code editor model.
+     */
+    model: CodeEditor.IModel;
+
     /**
      * The uuid of an editor.
      */
-    readonly uuid: string;
+    uuid: string;
 
     /**
      * A selection style.
      */
-    readonly selectionStyle?: CodeEditor.ISelectionStyle;
+    selectionStyle?: CodeEditor.ISelectionStyle;
   }
 }

+ 3 - 1
src/codemirror/factory.ts

@@ -26,6 +26,7 @@ class CodeMirrorEditorFactory implements IEditorFactory {
     return this.newEditor(host, {
       uuid: utils.uuid(),
       indentUnit: 4,
+      model: options.model,
       theme: DEFAULT_CODEMIRROR_THEME,
       extraKeys: {
         'Cmd-Right': 'goLineRight',
@@ -47,6 +48,7 @@ class CodeMirrorEditorFactory implements IEditorFactory {
   newDocumentEditor(host: HTMLElement, options: CodeEditor.IOptions): CodeEditor.IEditor {
     return this.newEditor(host, {
       uuid: utils.uuid(),
+      model: options.model,
       extraKeys: {
         'Tab': 'indentMore',
         'Shift-Enter': () => { /* no-op */ }
@@ -61,7 +63,7 @@ class CodeMirrorEditorFactory implements IEditorFactory {
   /**
    * Creates an editor and applies extra options.
    */
-  protected newEditor(host: HTMLElement, editorOptions: CodeMirrorEditor.IOptions, options: CodeEditor.IOptions) {
+  protected newEditor(host: HTMLElement, editorOptions: CodeMirrorEditor.IOptions, options: CodeEditor.IOptions): CodeEditor.IEditor {
     if (options.readOnly !== undefined) {
       editorOptions.readOnly = options.readOnly;
     }

+ 0 - 1
src/codemirror/index.ts

@@ -14,7 +14,6 @@ import {
 } from './mimetype';
 
 export * from './mode';
-export * from './model';
 export * from './editor';
 export * from './factory';
 export * from './mimetype';