diff options
Diffstat (limited to 'app/assets/javascripts/ide/components/repo_editor.vue')
-rw-r--r-- | app/assets/javascripts/ide/components/repo_editor.vue | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/app/assets/javascripts/ide/components/repo_editor.vue b/app/assets/javascripts/ide/components/repo_editor.vue index 56bbb6349cd..c8a825065f1 100644 --- a/app/assets/javascripts/ide/components/repo_editor.vue +++ b/app/assets/javascripts/ide/components/repo_editor.vue @@ -9,8 +9,8 @@ import { WEBIDE_MARK_FILE_START, WEBIDE_MEASURE_FILE_AFTER_INTERACTION, WEBIDE_MEASURE_FILE_FROM_REQUEST, -} from '~/performance_constants'; -import { performanceMarkAndMeasure } from '~/performance_utils'; +} from '~/performance/constants'; +import { performanceMarkAndMeasure } from '~/performance/utils'; import eventHub from '../eventhub'; import { leftSidebarViews, @@ -22,6 +22,7 @@ import Editor from '../lib/editor'; import FileTemplatesBar from './file_templates/bar.vue'; import { __ } from '~/locale'; import { extractMarkdownImagesFromEntries } from '../stores/utils'; +import { getFileEditorOrDefault } from '../stores/modules/editor/utils'; import { getPathParent, readFileAsDataURL, registerSchema, isTextFile } from '../utils'; import { getRulesWithTraversal } from '../lib/editorconfig/parser'; import mapRulesToMonaco from '../lib/editorconfig/rules_mapper'; @@ -49,6 +50,7 @@ export default { ...mapState('rightPane', { rightPaneIsOpen: 'isOpen', }), + ...mapState('editor', ['fileEditors']), ...mapState([ 'viewer', 'panelResizing', @@ -67,6 +69,9 @@ export default { 'getJsonSchemaForPath', ]), ...mapGetters('fileTemplates', ['showFileTemplatesBar']), + fileEditor() { + return getFileEditorOrDefault(this.fileEditors, this.file.path); + }, shouldHideEditor() { return this.file && !this.file.loading && !isTextFile(this.file); }, @@ -80,10 +85,10 @@ export default { return this.shouldHideEditor && this.file.mrChange && this.viewer === viewerTypes.mr; }, isEditorViewMode() { - return this.file.viewMode === FILE_VIEW_MODE_EDITOR; + return this.fileEditor.viewMode === FILE_VIEW_MODE_EDITOR; }, isPreviewViewMode() { - return this.file.viewMode === FILE_VIEW_MODE_PREVIEW; + return this.fileEditor.viewMode === FILE_VIEW_MODE_PREVIEW; }, editTabCSS() { return { @@ -125,8 +130,7 @@ export default { this.initEditor(); if (this.currentActivityView !== leftSidebarViews.edit.name) { - this.setFileViewMode({ - file: this.file, + this.updateEditor({ viewMode: FILE_VIEW_MODE_EDITOR, }); } @@ -134,8 +138,7 @@ export default { }, currentActivityView() { if (this.currentActivityView !== leftSidebarViews.edit.name) { - this.setFileViewMode({ - file: this.file, + this.updateEditor({ viewMode: FILE_VIEW_MODE_EDITOR, }); } @@ -195,13 +198,11 @@ export default { 'getFileData', 'getRawFileData', 'changeFileContent', - 'setFileLanguage', - 'setEditorPosition', - 'setFileViewMode', 'removePendingTab', 'triggerFilesChange', 'addTempImage', ]), + ...mapActions('editor', ['updateFileEditor']), initEditor() { if (this.shouldHideEditor && (this.file.content || this.file.raw)) { return; @@ -284,19 +285,19 @@ export default { // Handle Cursor Position this.editor.onPositionChange((instance, e) => { - this.setEditorPosition({ + this.updateEditor({ editorRow: e.position.lineNumber, editorColumn: e.position.column, }); }); this.editor.setPosition({ - lineNumber: this.file.editorRow, - column: this.file.editorColumn, + lineNumber: this.fileEditor.editorRow, + column: this.fileEditor.editorColumn, }); // Handle File Language - this.setFileLanguage({ + this.updateEditor({ fileLanguage: this.model.language, }); @@ -354,6 +355,16 @@ export default { const schema = this.getJsonSchemaForPath(this.file.path); registerSchema(schema); }, + updateEditor(data) { + // Looks like our model wrapper `.dispose` causes the monaco editor to emit some position changes after + // when disposing. We want to ignore these by only capturing editor changes that happen to the currently active + // file. + if (!this.file.active) { + return; + } + + this.updateFileEditor({ path: this.file.path, data }); + }, }, viewerTypes, FILE_VIEW_MODE_EDITOR, @@ -369,7 +380,7 @@ export default { <a href="javascript:void(0);" role="button" - @click.prevent="setFileViewMode({ file, viewMode: $options.FILE_VIEW_MODE_EDITOR })" + @click.prevent="updateEditor({ viewMode: $options.FILE_VIEW_MODE_EDITOR })" > {{ __('Edit') }} </a> @@ -378,7 +389,7 @@ export default { <a href="javascript:void(0);" role="button" - @click.prevent="setFileViewMode({ file, viewMode: $options.FILE_VIEW_MODE_PREVIEW })" + @click.prevent="updateEditor({ viewMode: $options.FILE_VIEW_MODE_PREVIEW })" >{{ previewMode.previewTitle }}</a > </li> |