|
@@ -18,7 +18,7 @@ import {
|
|
|
} from 'phosphor-di';
|
|
|
|
|
|
import {
|
|
|
- IEditor, IEditorFactory
|
|
|
+ IEditorHandler
|
|
|
} from './index';
|
|
|
|
|
|
import './plugin.css';
|
|
@@ -46,63 +46,56 @@ import './codemirror-ipython';
|
|
|
*/
|
|
|
export
|
|
|
function register(container: Container): void {
|
|
|
- container.register(IEditorFactory, EditorFactory);
|
|
|
+ container.register(IEditorHandler, EditorHandler);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * An implemenation of an IEditorFactory.
|
|
|
+ * An implemenation of an IEditorHandler.
|
|
|
*/
|
|
|
-class EditorFactory implements IEditorFactory {
|
|
|
+class EditorHandler implements IEditorHandler {
|
|
|
|
|
|
/**
|
|
|
- * The dependencies required by the editor factory.
|
|
|
+ * The dependencies required by the editor handler.
|
|
|
*/
|
|
|
static requires: Token<any>[] = [];
|
|
|
|
|
|
/**
|
|
|
- * Create a new editor factory instance.
|
|
|
+ * Create a new editor handler instance.
|
|
|
*/
|
|
|
- static create(): IEditorFactory {
|
|
|
- return new EditorFactory();
|
|
|
+ static create(): IEditorHandler {
|
|
|
+ return new EditorHandler();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Create a new IEditor instance.
|
|
|
*/
|
|
|
- createEditor(options?: CodeMirror.EditorConfiguration): IEditor {
|
|
|
- return new Editor(options);
|
|
|
+ createEditor(options?: CodeMirror.EditorConfiguration): CodeMirrorWidget {
|
|
|
+ return new CodeMirrorWidget(options);
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- * A default implementation of the jupyter editor widget.
|
|
|
- */
|
|
|
-class Editor extends CodeMirrorWidget {
|
|
|
|
|
|
/**
|
|
|
- * Get the text from the editor.
|
|
|
+ * A convenience method to get the text from the editor.
|
|
|
*/
|
|
|
- get text(): string {
|
|
|
- return this.editor.getDoc().getValue();
|
|
|
+ getText(widget: CodeMirrorWidget, text: string): string {
|
|
|
+ return widget.editor.getDoc().getValue();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set the text on the editor.
|
|
|
+ * A convenience method to set the text on the editor.
|
|
|
*/
|
|
|
- set text(value: string) {
|
|
|
- this.editor.getDoc().setValue(value);
|
|
|
+ setText(widget: CodeMirrorWidget, text: string): void {
|
|
|
+ widget.editor.getDoc().setValue(text);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Set the editor mode by name. This will lode the mode file
|
|
|
* as needed.
|
|
|
*/
|
|
|
- setModeByName(mode: string): void {
|
|
|
+ setModeByName(widget: CodeMirrorWidget, mode: string): void {
|
|
|
let info = CodeMirror.findModeByName(mode);
|
|
|
if (info) {
|
|
|
- this.loadCodeMirrorMode(info.mode, info.mime);
|
|
|
+ loadCodeMirrorMode(widget.editor, info.mode, info.mime);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -110,10 +103,10 @@ class Editor extends CodeMirrorWidget {
|
|
|
* Set the editor mode by file name. This will lode the mode file
|
|
|
* as needed.
|
|
|
*/
|
|
|
- setModeByFileName(filename: string): void {
|
|
|
+ setModeByFileName(widget: CodeMirrorWidget, filename: string): void {
|
|
|
let info = CodeMirror.findModeByFileName(filename);
|
|
|
if (info) {
|
|
|
- this.loadCodeMirrorMode(info.mode, info.mime);
|
|
|
+ loadCodeMirrorMode(widget.editor, info.mode, info.mime);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -121,27 +114,27 @@ class Editor extends CodeMirrorWidget {
|
|
|
* Set the editor mode by mime type. This will lode the mode file
|
|
|
* as needed.
|
|
|
*/
|
|
|
- setModeByMIMEType(mime: string): void {
|
|
|
+ setModeByMIMEType(widget: CodeMirrorWidget, mime: string): void {
|
|
|
let info = CodeMirror.findModeByMIME(mime);
|
|
|
if (info) {
|
|
|
- this.loadCodeMirrorMode(info.mode, info.mime);
|
|
|
+ loadCodeMirrorMode(widget.editor, info.mode, info.mime);
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- /**
|
|
|
- * Load and set a CodeMirror mode.
|
|
|
- *
|
|
|
- * #### Notes
|
|
|
- * This assumes WebPack as the module loader.
|
|
|
- */
|
|
|
- protected loadCodeMirrorMode(mode: string, mime: string): void {
|
|
|
- if (CodeMirror.modes.hasOwnProperty(mode)) {
|
|
|
- this.editor.setOption('mode', mime);
|
|
|
- } else {
|
|
|
- // Load the full codemirror mode bundle.
|
|
|
- require([`codemirror/mode/${mode}/${mode}.js`], () => {
|
|
|
- this.editor.setOption('mode', mime);
|
|
|
- });
|
|
|
- }
|
|
|
+/**
|
|
|
+ * Load and set a CodeMirror mode.
|
|
|
+ *
|
|
|
+ * #### Notes
|
|
|
+ * This assumes WebPack as the module loader.
|
|
|
+ */
|
|
|
+function loadCodeMirrorMode(editor: CodeMirror.Editor, mode: string, mime: string): void {
|
|
|
+ if (CodeMirror.modes.hasOwnProperty(mode)) {
|
|
|
+ editor.setOption('mode', mime);
|
|
|
+ } else {
|
|
|
+ // Load the full codemirror mode bundle.
|
|
|
+ require([`codemirror/mode/${mode}/${mode}.js`], () => {
|
|
|
+ editor.setOption('mode', mime);
|
|
|
+ });
|
|
|
}
|
|
|
}
|