Commit 3153d599 authored by Denys Mishunov's avatar Denys Mishunov

Keep Monaco in conditional imports

To avoid significant increase in webpack modules,
make sure Monaco imports are localized in the
conditionally loaded modules
parent e96ae9be
import $ from 'jquery';
import { Position } from 'monaco-editor';
import Api from '~/api';
import toast from '~/vue_shared/plugins/global_toast';
......@@ -191,14 +190,7 @@ export default class FileTemplateMediator {
this.editor.focus();
if (this.editor.navigateFileStart) {
// ACE. This will be removed and cleaned up
// in https://gitlab.com/gitlab-org/gitlab/-/issues/198610
this.editor.navigateFileStart();
} else {
// Editor Lite
this.editor.setPosition(new Position(1, 1));
}
}
findTemplateSelectorByKey(key) {
......
......@@ -40,9 +40,10 @@ export default class EditBlob {
const MarkdownExtensionPromise = this.options.isMarkdown
? import('~/editor/editor_markdown_ext')
: Promise.resolve(false);
const FileTemplateExtensionPromise = import('~/editor/editor_file_template_ext');
return Promise.all([EditorPromise, MarkdownExtensionPromise])
.then(([EditorModule, MarkdownExtension]) => {
return Promise.all([EditorPromise, MarkdownExtensionPromise, FileTemplateExtensionPromise])
.then(([EditorModule, MarkdownExtension, FileTemplateExtension]) => {
const EditorLite = EditorModule.default;
const editorEl = document.getElementById('editor');
const fileNameEl =
......@@ -58,9 +59,7 @@ export default class EditBlob {
blobContent: editorEl.innerText,
});
if (MarkdownExtension) {
rootEditor.use(MarkdownExtension.default, this.editor);
}
rootEditor.use([MarkdownExtension.default, FileTemplateExtension.default], this.editor);
fileNameEl.addEventListener('change', () => {
this.editor.updateModelLanguage(fileNameEl.value);
......
import { Position } from 'monaco-editor';
export default {
navigateFileStart() {
this.setPosition(new Position(1, 1));
},
};
......@@ -73,7 +73,6 @@ 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
......
import EditBlob from '~/blob_edit/edit_blob';
import EditorLite from '~/editor/editor_lite';
import MarkdownExtension from '~/editor/editor_markdown_ext';
import FileTemplateExtension from '~/editor/editor_file_template_ext';
jest.mock('~/editor/editor_lite');
jest.mock('~/editor/editor_markdown_ext');
......@@ -21,13 +22,29 @@ describe('Blob Editing', () => {
});
};
it('loads FileTemplateExtension by default', async () => {
await initEditor();
expect(EditorLite.prototype.use).toHaveBeenCalledWith(
expect.arrayContaining([FileTemplateExtension]),
mockInstance,
);
});
describe('Markdown', () => {
it('does not load MarkdownExtension by default', async () => {
await initEditor();
expect(EditorLite.prototype.use).not.toHaveBeenCalled();
expect(EditorLite.prototype.use).not.toHaveBeenCalledWith(
expect.arrayContaining([MarkdownExtension]),
mockInstance,
);
});
it('loads MarkdownExtension only for the markdown files', async () => {
await initEditor(true);
expect(EditorLite.prototype.use).toHaveBeenCalledWith(MarkdownExtension, mockInstance);
expect(EditorLite.prototype.use).toHaveBeenCalledWith(
[MarkdownExtension, FileTemplateExtension],
mockInstance,
);
});
});
});
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