Commit 8a6c04d1 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '273016-replace-ace-merge-conflicts' into 'master'

Replace ACE with Editor Lite

See merge request gitlab-org/gitlab!46250
parents 3dcc63fa f1542fb7
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
/* global ace */
import Vue from 'vue'; import Vue from 'vue';
import { debounce } from 'lodash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { deprecatedCreateFlash as flash } from '~/flash'; import { deprecatedCreateFlash as flash } from '~/flash';
import { __ } from '~/locale'; import { __ } from '~/locale';
import getModeByFileExtension from '~/lib/utils/ace_utils';
(global => { (global => {
global.mergeConflicts = global.mergeConflicts || {}; global.mergeConflicts = global.mergeConflicts || {};
...@@ -28,7 +27,6 @@ import getModeByFileExtension from '~/lib/utils/ace_utils'; ...@@ -28,7 +27,6 @@ import getModeByFileExtension from '~/lib/utils/ace_utils';
data() { data() {
return { return {
saved: false, saved: false,
loading: false,
fileLoaded: false, fileLoaded: false,
originalContent: '', originalContent: '',
}; };
...@@ -37,7 +35,6 @@ import getModeByFileExtension from '~/lib/utils/ace_utils'; ...@@ -37,7 +35,6 @@ import getModeByFileExtension from '~/lib/utils/ace_utils';
classObject() { classObject() {
return { return {
saved: this.saved, saved: this.saved,
'is-loading': this.loading,
}; };
}, },
}, },
...@@ -45,7 +42,7 @@ import getModeByFileExtension from '~/lib/utils/ace_utils'; ...@@ -45,7 +42,7 @@ import getModeByFileExtension from '~/lib/utils/ace_utils';
'file.showEditor': function showEditorWatcher(val) { 'file.showEditor': function showEditorWatcher(val) {
this.resetEditorContent(); this.resetEditorContent();
if (!val || this.fileLoaded || this.loading) { if (!val || this.fileLoaded) {
return; return;
} }
...@@ -59,30 +56,25 @@ import getModeByFileExtension from '~/lib/utils/ace_utils'; ...@@ -59,30 +56,25 @@ import getModeByFileExtension from '~/lib/utils/ace_utils';
}, },
methods: { methods: {
loadEditor() { loadEditor() {
this.loading = true; const EditorPromise = import(/* webpackChunkName: 'EditorLite' */ '~/editor/editor_lite');
const DataPromise = axios.get(this.file.content_path);
axios Promise.all([EditorPromise, DataPromise])
.get(this.file.content_path) .then(([{ default: EditorLite }, { data: { content, new_path: path } }]) => {
.then(({ data }) => { const contentEl = this.$el.querySelector('.editor');
const content = this.$el.querySelector('pre');
const fileContent = document.createTextNode(data.content);
content.textContent = fileContent.textContent; this.originalContent = content;
this.originalContent = data.content;
this.fileLoaded = true; this.fileLoaded = true;
this.editor = ace.edit(content);
this.editor.$blockScrolling = Infinity; // Turn off annoying warning this.editor = new EditorLite().createInstance({
this.editor.getSession().setMode(getModeByFileExtension(data.new_path)); el: contentEl,
this.editor.on('change', () => { blobPath: path,
this.saveDiffResolution(); blobContent: content,
}); });
this.saveDiffResolution(); this.editor.onDidChangeModelContent(debounce(this.saveDiffResolution.bind(this), 250));
this.loading = false;
}) })
.catch(() => { .catch(() => {
flash(__('An error occurred while loading the file')); flash(__('An error occurred while loading the file'));
this.loading = false;
}); });
}, },
saveDiffResolution() { saveDiffResolution() {
...@@ -95,7 +87,7 @@ import getModeByFileExtension from '~/lib/utils/ace_utils'; ...@@ -95,7 +87,7 @@ import getModeByFileExtension from '~/lib/utils/ace_utils';
}, },
resetEditorContent() { resetEditorContent() {
if (this.fileLoaded) { if (this.fileLoaded) {
this.editor.setValue(this.originalContent, -1); this.editor.setValue(this.originalContent);
} }
}, },
cancelDiscardConfirmation(file) { cancelDiscardConfirmation(file) {
......
...@@ -8,18 +8,18 @@ ...@@ -8,18 +8,18 @@
background: $gray-normal; background: $gray-normal;
} }
#editor { #editor,
border: 0; .editor {
border-radius: 0; @include gl-border-0;
@include gl-m-0;
@include gl-p-0;
@include gl-relative;
@include gl-w-full;
height: 500px; height: 500px;
margin: 0;
padding: 0;
position: relative;
width: 100%;
.editor-loading-content { .editor-loading-content {
height: 100%; @include gl-h-full;
border: 0; @include gl-border-0;
} }
} }
......
...@@ -7,7 +7,4 @@ ...@@ -7,7 +7,4 @@
%button.btn.btn-sm.btn-close{ "@click" => "acceptDiscardConfirmation(file)" } Discard changes %button.btn.btn-sm.btn-close{ "@click" => "acceptDiscardConfirmation(file)" } Discard changes
%button.btn.btn-sm{ "@click" => "cancelDiscardConfirmation(file)" } Cancel %button.btn.btn-sm{ "@click" => "cancelDiscardConfirmation(file)" } Cancel
.editor-wrap{ ":class" => "classObject" } .editor-wrap{ ":class" => "classObject" }
.loading .editor{ "style" => "height: 350px", data: { 'editor-loading': true } }
.spinner.spinner-md
.editor
%pre{ "style" => "height: 350px" }
---
title: Replace ACE with Editor Lite
merge_request: 46250
author:
type: changed
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Merge request > User resolves conflicts', :js do RSpec.describe 'Merge request > User resolves conflicts', :js do
include Spec::Support::Helpers::Features::EditorLiteSpecHelpers
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { project.creator } let(:user) { project.creator }
...@@ -64,15 +66,13 @@ RSpec.describe 'Merge request > User resolves conflicts', :js do ...@@ -64,15 +66,13 @@ RSpec.describe 'Merge request > User resolves conflicts', :js do
within find('.files-wrapper .diff-file', text: 'files/ruby/popen.rb') do within find('.files-wrapper .diff-file', text: 'files/ruby/popen.rb') do
click_button 'Edit inline' click_button 'Edit inline'
wait_for_requests wait_for_requests
find('.files-wrapper .diff-file pre') editor_set_value("One morning")
execute_script('ace.edit($(".files-wrapper .diff-file pre")[0]).setValue("One morning");')
end end
within find('.files-wrapper .diff-file', text: 'files/ruby/regex.rb') do within find('.files-wrapper .diff-file', text: 'files/ruby/regex.rb') do
click_button 'Edit inline' click_button 'Edit inline'
wait_for_requests wait_for_requests
find('.files-wrapper .diff-file pre') editor_set_value("Gregor Samsa woke from troubled dreams")
execute_script('ace.edit($(".files-wrapper .diff-file pre")[1]).setValue("Gregor Samsa woke from troubled dreams");')
end end
find_button('Commit to source branch').send_keys(:return) find_button('Commit to source branch').send_keys(:return)
......
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