浏览代码

initial attempt at codemirror singleton

Nicholas Bollweg 4 年之前
父节点
当前提交
f08ee87cfd
共有 3 个文件被更改,包括 44 次插入3 次删除
  1. 20 2
      packages/codemirror-extension/src/index.ts
  2. 3 1
      packages/codemirror/src/index.ts
  3. 21 0
      packages/codemirror/src/tokens.ts

+ 20 - 2
packages/codemirror-extension/src/index.ts

@@ -19,7 +19,8 @@ import {
   editorServices,
   EditorSyntaxStatus,
   CodeMirrorEditor,
-  Mode
+  Mode,
+  ICodeMirror
 } from '@jupyterlab/codemirror';
 
 import { IDocumentWidget } from '@jupyterlab/docregistry';
@@ -47,6 +48,13 @@ namespace CommandIDs {
   export const goToLine = 'codemirror:go-to-line';
 }
 
+/** The CodeMirror singleton. */
+const codemirrorSingleton: JupyterFrontEndPlugin<ICodeMirror> = {
+  id: '@jupyterlab/codemirror-extension:codemirror',
+  provides: ICodeMirror,
+  activate: activateCodeMirror
+}
+
 /**
  * The editor services.
  */
@@ -116,7 +124,8 @@ export const editorSyntaxStatus: JupyterFrontEndPlugin<void> = {
 const plugins: JupyterFrontEndPlugin<any>[] = [
   commands,
   services,
-  editorSyntaxStatus
+  editorSyntaxStatus,
+  codemirrorSingleton
 ];
 export default plugins;
 
@@ -135,6 +144,15 @@ function activateEditorServices(app: JupyterFrontEnd): IEditorServices {
   return editorServices;
 }
 
+/**
+ * Set up the CodeMirror singleton.
+ */
+function activateCodeMirror(app: JupyterFrontEnd): ICodeMirror {
+  return {
+    codemirrorSingleton: () => CodeMirror
+  }
+}
+
 /**
  * Set up the editor widget menu and commands.
  */

+ 3 - 1
packages/codemirror/src/index.ts

@@ -13,6 +13,8 @@ export * from './factory';
 export * from './mimetype';
 export * from './syntaxstatus';
 
+export * from './tokens';
+
 /**
  * The default editor services.
  */
@@ -23,7 +25,7 @@ export const editorServices: IEditorServices = {
 
 /**
  * FIXME-TRANS: Maybe an option to be able to pass a translator to the factories?
- * 
+ *
 
 export function getEditorServices(translator: ITranslator): IEditorServices {
   return {

+ 21 - 0
packages/codemirror/src/tokens.ts

@@ -0,0 +1,21 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import { Token } from '@lumino/coreutils';
+
+import CodeMirror from 'codemirror';
+
+/* tslint:disable */
+/**
+ * The CodeMirror token.
+ */
+export const ICodeMirror = new Token<ICodeMirror>('@jupyterlab/codemirror:ICodeMirror');
+/* tslint:enable */
+
+/** The CodeMirror interface. */
+export interface ICodeMirror {
+  /**
+   * A singleton CodeMirror module, rexported.
+   */
+  codemirrorSingleton(): typeof CodeMirror;
+}