Commit ad5667ae authored by Denys Mishunov's avatar Denys Mishunov

Moved out decoration functions to external fns

Aslso re-named some functions to match the naming
parent 3f079d84
...@@ -137,26 +137,34 @@ export default class EditorLite { ...@@ -137,26 +137,34 @@ export default class EditorLite {
static convertMonacoToELInstance = (inst) => { static convertMonacoToELInstance = (inst) => {
const decoratedInstance = inst; const decoratedInstance = inst;
decoratedInstance.updateModelLanguage = (path) => { decoratedInstance.updateModelLanguage = (path) => {
const lang = EditorLite.getModelLanguage(path); return EditorLite.instanceUpdateLanguage(inst, path);
const model = decoratedInstance.getModel();
return monacoEditor.setModelLanguage(model, lang);
}; };
decoratedInstance.use = (exts = []) => { decoratedInstance.use = (exts = []) => {
const extensions = Array.isArray(exts) ? exts : [exts]; return EditorLite.instanceApplyExtension(inst, exts);
extensions.forEach((extension) => {
EditorLite.mixIntoInstance(extension, decoratedInstance);
});
return decoratedInstance;
}; };
return decoratedInstance; return decoratedInstance;
}; };
static removeInstanceFromRegistry(editor, instance) { static instanceUpdateLanguage(inst, path) {
const lang = EditorLite.getModelLanguage(path);
const model = inst.getModel();
return monacoEditor.setModelLanguage(model, lang);
}
static instanceApplyExtension(inst, exts = []) {
const extensions = Array.isArray(exts) ? exts : [exts];
extensions.forEach((extension) => {
EditorLite.mixIntoInstance(extension, inst);
});
return inst;
}
static instanceRemoveFromRegistry(editor, instance) {
const index = editor.instances.findIndex((inst) => inst === instance); const index = editor.instances.findIndex((inst) => inst === instance);
editor.instances.splice(index, 1); editor.instances.splice(index, 1);
} }
static disposeInstanceModels(editor, instance, model) { static instanceDisposeModels(editor, instance, model) {
const instanceModel = instance.getModel() || model; const instanceModel = instance.getModel() || model;
if (!instanceModel) { if (!instanceModel) {
return; return;
...@@ -216,8 +224,8 @@ export default class EditorLite { ...@@ -216,8 +224,8 @@ export default class EditorLite {
} }
instance.onDidDispose(() => { instance.onDidDispose(() => {
EditorLite.removeInstanceFromRegistry(this, instance); EditorLite.instanceRemoveFromRegistry(this, instance);
EditorLite.disposeInstanceModels(this, instance, model); EditorLite.instanceDisposeModels(this, instance, model);
}); });
EditorLite.manageDefaultExtensions(instance, el, extensions); EditorLite.manageDefaultExtensions(instance, el, extensions);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment