-
Notifications
You must be signed in to change notification settings - Fork 1
/
EditorInitializer.js
49 lines (41 loc) · 1.61 KB
/
EditorInitializer.js
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
class EditorInitializer {
constructor(monacoInstance, editorContainer, editorTheme, initialContent) {
this.monaco = monacoInstance;
this.editorContainer = editorContainer;
this.editorTheme = editorTheme;
this.initialContent = initialContent;
}
initialize() {
const editor = this._createEditor();
this._configureEditor(editor);
this._applyTheme();
return editor;
}
_createEditor() {
return this.monaco.editor.create(this.editorContainer, {
automaticLayout: true,
fontSize: 16,
language: 'xml',
value: this.initialContent,
minimap: { enabled: true },
});
}
_configureEditor(editor) {
const triggerSuggestCommand = this.monaco.KeyMod.Alt | this.monaco.KeyCode.Space;
const contextCondition = 'editorTextFocus && !editorHasSelection && ' +
'!editorHasMultipleSelections && !editorTabMovesFocus && ' +
'!hasQuickSuggest';
editor.addCommand(triggerSuggestCommand, () => {
editor.trigger('', 'editor.action.triggerSuggest', '');
}, contextCondition);
}
_applyTheme() {
this.monaco.editor.defineTheme('customTheme', this.editorTheme);
this.monaco.editor.setTheme('customTheme');
}
}
export default EditorInitializer;