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 $ from 'jquery';
import { Position } from 'monaco-editor';
import Api from '~/api'; import Api from '~/api';
import toast from '~/vue_shared/plugins/global_toast'; import toast from '~/vue_shared/plugins/global_toast';
...@@ -191,14 +190,7 @@ export default class FileTemplateMediator { ...@@ -191,14 +190,7 @@ export default class FileTemplateMediator {
this.editor.focus(); this.editor.focus();
if (this.editor.navigateFileStart) { 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) { findTemplateSelectorByKey(key) {
......
...@@ -40,9 +40,10 @@ export default class EditBlob { ...@@ -40,9 +40,10 @@ export default class EditBlob {
const MarkdownExtensionPromise = this.options.isMarkdown const MarkdownExtensionPromise = this.options.isMarkdown
? import('~/editor/editor_markdown_ext') ? import('~/editor/editor_markdown_ext')
: Promise.resolve(false); : Promise.resolve(false);
const FileTemplateExtensionPromise = import('~/editor/editor_file_template_ext');
return Promise.all([EditorPromise, MarkdownExtensionPromise]) return Promise.all([EditorPromise, MarkdownExtensionPromise, FileTemplateExtensionPromise])
.then(([EditorModule, MarkdownExtension]) => { .then(([EditorModule, MarkdownExtension, FileTemplateExtension]) => {
const EditorLite = EditorModule.default; const EditorLite = EditorModule.default;
const editorEl = document.getElementById('editor'); const editorEl = document.getElementById('editor');
const fileNameEl = const fileNameEl =
...@@ -58,9 +59,7 @@ export default class EditBlob { ...@@ -58,9 +59,7 @@ export default class EditBlob {
blobContent: editorEl.innerText, blobContent: editorEl.innerText,
}); });
if (MarkdownExtension) { rootEditor.use([MarkdownExtension.default, FileTemplateExtension.default], this.editor);
rootEditor.use(MarkdownExtension.default, this.editor);
}
fileNameEl.addEventListener('change', () => { fileNameEl.addEventListener('change', () => {
this.editor.updateModelLanguage(fileNameEl.value); 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 { ...@@ -73,7 +73,6 @@ export default class Editor {
this.instances.splice(index, 1); this.instances.splice(index, 1);
model.dispose(); model.dispose();
}); });
instance.updateModelLanguage = path => this.updateModelLanguage(path); instance.updateModelLanguage = path => this.updateModelLanguage(path);
// Reference to the model on the editor level will go away in // Reference to the model on the editor level will go away in
......
import EditBlob from '~/blob_edit/edit_blob'; import EditBlob from '~/blob_edit/edit_blob';
import EditorLite from '~/editor/editor_lite'; import EditorLite from '~/editor/editor_lite';
import MarkdownExtension from '~/editor/editor_markdown_ext'; import MarkdownExtension from '~/editor/editor_markdown_ext';
import FileTemplateExtension from '~/editor/editor_file_template_ext';
jest.mock('~/editor/editor_lite'); jest.mock('~/editor/editor_lite');
jest.mock('~/editor/editor_markdown_ext'); jest.mock('~/editor/editor_markdown_ext');
...@@ -21,13 +22,29 @@ describe('Blob Editing', () => { ...@@ -21,13 +22,29 @@ describe('Blob Editing', () => {
}); });
}; };
it('does not load MarkdownExtension by default', async () => { it('loads FileTemplateExtension by default', async () => {
await initEditor(); await initEditor();
expect(EditorLite.prototype.use).not.toHaveBeenCalled(); expect(EditorLite.prototype.use).toHaveBeenCalledWith(
expect.arrayContaining([FileTemplateExtension]),
mockInstance,
);
}); });
it('loads MarkdownExtension only for the markdown files', async () => { describe('Markdown', () => {
await initEditor(true); it('does not load MarkdownExtension by default', async () => {
expect(EditorLite.prototype.use).toHaveBeenCalledWith(MarkdownExtension, mockInstance); await initEditor();
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, 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