浏览代码

Set matchbrackets and autoclosebrackets based on mimetype

Steven Silvester 8 年之前
父节点
当前提交
7cebf44941
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9 4
      src/codemirror/editor.ts

+ 9 - 4
src/codemirror/editor.ts

@@ -67,7 +67,9 @@ class CodeMirrorEditor implements CodeEditor.IEditor {
     options.value = this._model.doc;
     this._editor = CodeMirror(host, options);
 
-    this._model.mimeTypeChanged.connect((model, args) => this._onMimeTypeChanged(model, args));
+    this._onMimeTypeChanged();
+    // TODO: handle initial selections.
+    this._model.mimeTypeChanged.connect(() => this._onMimeTypeChanged());
     this._model.selections.changed.connect((selections, args) => this._onSelectionsChanged(selections, args));
 
     CodeMirror.on(this.editor, 'keydown', (editor, event) => this._onKeyDown(editor, event));
@@ -278,9 +280,12 @@ class CodeMirrorEditor implements CodeEditor.IEditor {
   /**
    * Handles a mime type change.
    */
-  protected _onMimeTypeChanged(model: CodeMirrorModel, args: IChangedArgs<string>): void {
-      const mime = args.newValue;
-      loadModeByMIME(this._editor, mime);
+  protected _onMimeTypeChanged(): void {
+    const mime = this._model.mimeType;
+    loadModeByMIME(this._editor, mime);
+    let isCode = (mime !== 'text/plain') && (mime !== 'text/x-ipythongfm');
+    this.editor.setOption('matchBrackets', isCode);
+    this.editor.setOption('autoCloseBrackets', isCode);
   }
 
   /**