Sfoglia il codice sorgente

wip codemirror updates

Steven Silvester 7 anni fa
parent
commit
a60971f3ab

+ 6 - 20
packages/codemirror/src/mimetype.ts

@@ -25,25 +25,12 @@ class CodeMirrorMimeTypeService implements IEditorMimeTypeService {
    * If a mime type cannot be found returns the defaul mime type `text/plain`, never `null`.
    * If a mime type cannot be found returns the defaul mime type `text/plain`, never `null`.
    */
    */
   getMimeTypeByLanguage(info: nbformat.ILanguageInfoMetadata): string {
   getMimeTypeByLanguage(info: nbformat.ILanguageInfoMetadata): string {
-    let mode: Mode.ISpec;
-    if (info.codemirror_mode) {
-      mode = Mode.findBest(info.codemirror_mode as any);
-      if (mode) {
-        return mode.mime;
-      }
-    }
-    mode = Mode.findByMIME(info.mimetype || '');
-    if (mode) {
-      return info.mimetype!;
-    }
     let ext = info.file_extension || '';
     let ext = info.file_extension || '';
-    ext = ext.split('.').slice(-1)[0];
-    mode = Mode.findByExtension(ext || '');
-    if (mode) {
-      return mode.mime;
-    }
-    mode = Mode.findByName(info.name || '');
-    return mode ? mode.mime : IEditorMimeTypeService.defaultMimeType;
+    return Mode.findBest(info.codemirror_mode as any || {
+      mimetype: info.mimetype,
+      name: info.name,
+      ext: [ext.split('.').slice(-1)[0]]
+    }).mime;
   }
   }
 
 
   /**
   /**
@@ -56,7 +43,6 @@ class CodeMirrorMimeTypeService implements IEditorMimeTypeService {
     if (PathExt.extname(path) === '.ipy') {
     if (PathExt.extname(path) === '.ipy') {
       return 'text/x-python';
       return 'text/x-python';
     }
     }
-    const mode = Mode.findByFileName(path);
-    return mode ? mode.mime : IEditorMimeTypeService.defaultMimeType;
+    return Mode.findBest(path).mime;
   }
   }
 }
 }

+ 9 - 3
packages/codemirror/src/mode.ts

@@ -1,6 +1,10 @@
 // Copyright (c) Jupyter Development Team.
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 // Distributed under the terms of the Modified BSD License.
 
 
+import {
+  IEditorMimeTypeService
+} from '@jupyterlab/codeeditor';
+
 import * as CodeMirror
 import * as CodeMirror
   from 'codemirror';
   from 'codemirror';
 
 
@@ -89,11 +93,13 @@ namespace Mode {
     let modename = (typeof mode === 'string') ? mode :
     let modename = (typeof mode === 'string') ? mode :
         mode.mode || mode.name;
         mode.mode || mode.name;
     let mimetype = (typeof mode !== 'string') ? mode.mime : modename;
     let mimetype = (typeof mode !== 'string') ? mode.mime : modename;
+    let ext = (typeof mode !== 'string') ? mode.ext : [];
 
 
     return (
     return (
       CodeMirror.findModeByName(modename || '') ||
       CodeMirror.findModeByName(modename || '') ||
       CodeMirror.findModeByMIME(mimetype || '') ||
       CodeMirror.findModeByMIME(mimetype || '') ||
-      CodeMirror.findModeByMIME('text/plain')
+      CodeMirror.findModeByExt(ext) ||
+      CodeMirror.findModeByMIME(IEditorMimeTypeService.defaultMimeType)
     );
     );
   }
   }
 
 
@@ -109,8 +115,8 @@ namespace Mode {
    * Find a codemirror mode by name.
    * Find a codemirror mode by name.
    */
    */
   export
   export
-  function findByName(mime: string): ISpec {
-    return CodeMirror.findModeByName(mime);
+  function findByName(name: string): ISpec {
+    return CodeMirror.findModeByName(name);
   }
   }
 
 
   /**
   /**

+ 0 - 27
packages/codemirror/style/index.css

@@ -120,33 +120,6 @@
   white-space: nowrap;
   white-space: nowrap;
 }
 }
 
 
-.CodeMirror-vscrollbar::-webkit-scrollbar, .CodeMirror-hscrollbar::-webkit-scrollbar {
-  background-color: var(--jp-layout-color0);
-  width: var(--jp-scrollbar-width);
-}
-
-.CodeMirror-vscrollbar::-webkit-scrollbar {
-  border-left: 1px solid var(--jp-border-color1);
-}
-
-.CodeMirror-hscrollbar::-webkit-scrollbar {
-  border-top: 1px solid var(--jp-border-color1);
-}
-
-.CodeMirror-vscrollbar::-webkit-scrollbar-thumb, .CodeMirror-hscrollbar::-webkit-scrollbar-thumb {
-  background-color: var(--jp-layout-color2);
-  border-radius: 0px;
-}
-
-.CodeMirror-vscrollbar::-webkit-scrollbar-thumb {
-  border-left: 1px solid var(--jp-border-color1);
-}
-
-.CodeMirror-hscrollbar::-webkit-scrollbar-thumb {
-  border-top: 1px solid var(--jp-border-color1);
-}
-
-
 
 
 /*
 /*
   Here is our jupyter theme for CodeMirror syntax highlighting
   Here is our jupyter theme for CodeMirror syntax highlighting