forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.ts
73 lines (65 loc) · 1.86 KB
/
factory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
CodeEditor, IEditorFactoryService
} from '@jupyterlab/codeeditor';
import {
CodeMirrorEditor
} from './editor';
/**
* CodeMirror editor factory.
*/
export
class CodeMirrorEditorFactory implements IEditorFactoryService {
/**
* Construct an IEditorFactoryService for CodeMirrorEditors.
*/
constructor(defaults: Partial<CodeMirrorEditor.IConfig> = {}) {
this.inlineCodeMirrorConfig = {
...CodeMirrorEditor.defaultConfig,
extraKeys: {
'Cmd-Right': 'goLineRight',
'End': 'goLineRight',
'Cmd-Left': 'goLineLeft',
'Tab': 'indentMoreOrinsertTab',
'Shift-Tab': 'indentLess',
'Cmd-/': 'toggleComment',
'Ctrl-/': 'toggleComment',
},
...defaults
};
this.documentCodeMirrorConfig = {
...CodeMirrorEditor.defaultConfig,
extraKeys: {
'Tab': 'indentMoreOrinsertTab',
'Shift-Tab': 'indentLess',
'Shift-Enter': () => { /* no-op */ }
},
lineNumbers: true,
scrollPastEnd: true,
...defaults
};
}
/**
* Create a new editor for inline code.
*/
newInlineEditor = (options: CodeEditor.IOptions) => {
options.host.dataset.type = 'inline';
return new CodeMirrorEditor({
...options,
config: { ...this.inlineCodeMirrorConfig, ...options.config || {} }
});
}
/**
* Create a new editor for a full document.
*/
newDocumentEditor = (options: CodeEditor.IOptions) => {
options.host.dataset.type = 'document';
return new CodeMirrorEditor({
...options,
config: { ...this.documentCodeMirrorConfig, ...options.config || {} }
});
}
protected inlineCodeMirrorConfig: Partial<CodeMirrorEditor.IConfig>;
protected documentCodeMirrorConfig: Partial<CodeMirrorEditor.IConfig>;
}