Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-04 09:09:04 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-04 09:09:04 +0300
commita01d39d8ded394155227dad65408761021bf1092 (patch)
treee6b98cb4e552b846b289f96c061104be28b511f7 /app/assets/javascripts/editor
parent583bde3f83951fa4c294804edc2e9c57fb293733 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/editor')
-rw-r--r--app/assets/javascripts/editor/editor_lite.js51
1 files changed, 18 insertions, 33 deletions
diff --git a/app/assets/javascripts/editor/editor_lite.js b/app/assets/javascripts/editor/editor_lite.js
index 136a232d9d0..bbd5461ae4d 100644
--- a/app/assets/javascripts/editor/editor_lite.js
+++ b/app/assets/javascripts/editor/editor_lite.js
@@ -9,11 +9,7 @@ import { EDITOR_LITE_INSTANCE_ERROR_NO_EL, URI_PREFIX } from './constants';
export default class Editor {
constructor(options = {}) {
- this.editorEl = null;
- this.blobContent = '';
- this.blobPath = '';
this.instances = [];
- this.model = null;
this.options = {
extraEditorClassName: 'gl-editor-lite',
...defaultEditorOptions,
@@ -32,6 +28,17 @@ export default class Editor {
monacoEditor.setTheme(theme ? themeName : DEFAULT_THEME);
}
+ static updateModelLanguage(path, instance) {
+ if (!instance) return;
+ const model = instance.getModel();
+ const ext = `.${path.split('.').pop()}`;
+ const language = monacoLanguages
+ .getLanguages()
+ .find(lang => lang.extensions.indexOf(ext) !== -1);
+ const id = language ? language.id : 'plaintext';
+ monacoEditor.setModelLanguage(model, id);
+ }
+
/**
* Creates a monaco instance with the given options.
*
@@ -51,19 +58,18 @@ export default class Editor {
if (!el) {
throw new Error(EDITOR_LITE_INSTANCE_ERROR_NO_EL);
}
- this.editorEl = el;
- this.blobContent = blobContent;
- this.blobPath = blobPath;
- clearDomElement(this.editorEl);
+ clearDomElement(el);
const uriFilePath = joinPaths(URI_PREFIX, blobGlobalId, blobPath);
- const model = monacoEditor.createModel(this.blobContent, undefined, Uri.file(uriFilePath));
+ const model = monacoEditor.createModel(blobContent, undefined, Uri.file(uriFilePath));
- monacoEditor.onDidCreateEditor(this.renderEditor.bind(this));
+ monacoEditor.onDidCreateEditor(() => {
+ delete el.dataset.editorLoading;
+ });
- const instance = monacoEditor.create(this.editorEl, {
+ const instance = monacoEditor.create(el, {
...this.options,
...instanceOptions,
});
@@ -73,13 +79,7 @@ export default class Editor {
this.instances.splice(index, 1);
model.dispose();
});
- instance.updateModelLanguage = path => this.updateModelLanguage(path);
-
- // Reference to the model on the editor level will go away in
- // https://gitlab.com/gitlab-org/gitlab/-/issues/241023
- // After that, the references to the model will be routed through
- // instance exclusively
- this.model = model;
+ instance.updateModelLanguage = path => Editor.updateModelLanguage(path, instance);
this.instances.push(instance);
return instance;
@@ -89,21 +89,6 @@ export default class Editor {
this.instances.forEach(instance => instance.dispose());
}
- renderEditor() {
- delete this.editorEl.dataset.editorLoading;
- }
-
- updateModelLanguage(path) {
- if (path === this.blobPath) return;
- this.blobPath = path;
- const ext = `.${path.split('.').pop()}`;
- const language = monacoLanguages
- .getLanguages()
- .find(lang => lang.extensions.indexOf(ext) !== -1);
- const id = language ? language.id : 'plaintext';
- monacoEditor.setModelLanguage(this.model, id);
- }
-
use(exts = [], instance = null) {
const extensions = Array.isArray(exts) ? exts : [exts];
if (instance) {