浏览代码

[codemirror] Separate factory from editor

akosyakov 8 年之前
父节点
当前提交
8b102a6078
共有 2 个文件被更改,包括 56 次插入41 次删除
  1. 1 41
      src/codemirror/editor.ts
  2. 55 0
      src/codemirror/factory.ts

+ 1 - 41
src/codemirror/editor.ts

@@ -9,7 +9,7 @@ import {
 } from './';
 
 import {
-  CodeEditor, IEditorFactory
+  CodeEditor
 } from '../codeeditor';
 
 import {
@@ -275,43 +275,3 @@ class CodeMirrorEditor implements CodeEditor.IEditor {
   private _isDisposed = false;
 
 }
-
-export
-class CodeMirrorEditorFactory implements IEditorFactory {
-
-  /**
-   * Create a new editor for inline code.
-   */
-  newInlineEditor(host: HTMLElement, option: CodeEditor.IOptions): CodeEditor.IEditor {
-    let editor = new CodeMirrorEditor(host, {
-      extraKeys: {
-        'Tab': 'indentMore',
-        'Shift-Enter': () => { /* no-op */ }
-      },
-      indentUnit: 4,
-      theme: DEFAULT_CODEMIRROR_THEME,
-      lineNumbers: true,
-      lineWrapping: true,
-    });
-    // TODO configure inline editor
-    return editor;
-  }
-
-  /**
-   * Create a new editor for a full document.
-   */
-  newDocumentEditor(host: HTMLElement, options: CodeEditor.IOptions): CodeEditor.IEditor {
-    let editor = new CodeMirrorEditor(host, {
-      extraKeys: {
-        'Tab': 'indentMore',
-        'Shift-Enter': () => { /* no-op */ }
-      },
-      indentUnit: 4,
-      theme: DEFAULT_CODEMIRROR_THEME,
-      lineNumbers: true,
-      lineWrapping: true,
-    });
-    return editor;
-  }
-
-}

+ 55 - 0
src/codemirror/factory.ts

@@ -0,0 +1,55 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import {
+  CodeEditor, IEditorFactory
+} from '../codeeditor';
+
+import {
+  CodeMirrorEditor, DEFAULT_CODEMIRROR_THEME
+} from './editor';
+
+export
+class CodeMirrorEditorFactory implements IEditorFactory {
+
+  /**
+   * Create a new editor for inline code.
+   */
+  newInlineEditor(host: HTMLElement, option: CodeEditor.IOptions): CodeEditor.IEditor {
+    // FIXME: merge given options
+    return new CodeMirrorEditor(host, {
+      indentUnit: 4,
+      readOnly: false,
+      extraKeys: {
+        'Cmd-Right': 'goLineRight',
+        'End': 'goLineRight',
+        'Cmd-Left': 'goLineLeft',
+        'Tab': 'indentMore',
+        'Shift-Tab': 'indentLess',
+        'Cmd-Alt-[': 'indentAuto',
+        'Ctrl-Alt-[': 'indentAuto',
+        'Cmd-/': 'toggleComment',
+        'Ctrl-/': 'toggleComment',
+      },
+      lineNumbers: true,
+      lineWrapping: true,
+    });
+  }
+
+  /**
+   * Create a new editor for a full document.
+   */
+  newDocumentEditor(host: HTMLElement, options: CodeEditor.IOptions): CodeEditor.IEditor {
+    return new CodeMirrorEditor(host, {
+      extraKeys: {
+        'Tab': 'indentMore',
+        'Shift-Enter': () => { /* no-op */ }
+      },
+      indentUnit: 4,
+      theme: DEFAULT_CODEMIRROR_THEME,
+      lineNumbers: true,
+      lineWrapping: true,
+    });
+  }
+
+}