diff options
5 files changed, 25 insertions, 8 deletions
diff --git a/app/assets/javascripts/ide/components/commit_sidebar/list_item.vue b/app/assets/javascripts/ide/components/commit_sidebar/list_item.vue index 6d4e79f2d7a..a79d0640913 100644 --- a/app/assets/javascripts/ide/components/commit_sidebar/list_item.vue +++ b/app/assets/javascripts/ide/components/commit_sidebar/list_item.vue @@ -29,7 +29,13 @@ export default { }, }, methods: { - ...mapActions(['discardFileChanges', 'updateViewer', 'openPendingTab']), + ...mapActions([ + 'discardFileChanges', + 'updateViewer', + 'openPendingTab', + 'unstageChange', + 'stageChange', + ]), openFileInEditor() { return this.openPendingTab({ file: this.file, diff --git a/app/assets/javascripts/ide/components/repo_editor.vue b/app/assets/javascripts/ide/components/repo_editor.vue index 43c5c47b951..c4dd29f5192 100644 --- a/app/assets/javascripts/ide/components/repo_editor.vue +++ b/app/assets/javascripts/ide/components/repo_editor.vue @@ -69,7 +69,13 @@ export default { path: this.file.path, baseSha: this.currentMergeRequest ? this.currentMergeRequest.baseCommitSha : '', }) - .then(() => this.updateViewer(this.file.pending ? 'diff' : this.viewer)) + .then(() => { + const viewerPromise = this.delayViewerUpdated + ? this.updateViewer('editor') + : Promise.resolve(); + + return viewerPromise; + }) .then(() => { this.updateDelayViewerUpdated(false); this.createEditorInstance(); diff --git a/app/assets/javascripts/ide/lib/common/model.js b/app/assets/javascripts/ide/lib/common/model.js index 1475d6b9ce0..31987c7aa32 100644 --- a/app/assets/javascripts/ide/lib/common/model.js +++ b/app/assets/javascripts/ide/lib/common/model.js @@ -34,10 +34,12 @@ export default class Model { this.events = new Map(); this.updateContent = this.updateContent.bind(this); + this.updateNewContent = this.updateNewContent.bind(this); this.dispose = this.dispose.bind(this); eventHub.$on(`editor.update.model.dispose.${this.file.key}`, this.dispose); eventHub.$on(`editor.update.model.content.${this.file.key}`, this.updateContent); + eventHub.$on(`editor.update.model.new.content.${this.file.key}`, this.updateNewContent); } get url() { @@ -87,11 +89,16 @@ export default class Model { } } + updateNewContent(content) { + this.getModel().setValue(content); + } + dispose() { this.disposable.dispose(); this.events.clear(); eventHub.$off(`editor.update.model.dispose.${this.file.key}`, this.dispose); eventHub.$off(`editor.update.model.content.${this.file.key}`, this.updateContent); + eventHub.$off(`editor.update.model.new.content.${this.file.key}`, this.updateNewContent); } } diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js index de98ebc8ebb..1331a0ee441 100644 --- a/app/assets/javascripts/ide/stores/actions/file.js +++ b/app/assets/javascripts/ide/stores/actions/file.js @@ -174,10 +174,7 @@ export const stageChange = ({ commit, state }, path) => { commit(types.STAGE_CHANGE, path); if (stagedFile) { - eventHub.$emit(`editor.update.model.content.staged-${stagedFile.key}`, { - content: stagedFile.content, - changed: false, - }); + eventHub.$emit(`editor.update.model.new.content.staged-${stagedFile.key}`, stagedFile.content); } }; @@ -186,7 +183,7 @@ export const unstageChange = ({ commit }, path) => { }; export const openPendingTab = ({ commit, getters, dispatch, state }, { file, keyPrefix }) => { - if (getters.activeFile && getters.activeFile.path === file.path && state.viewer === 'diff') { + if (getters.activeFile && getters.activeFile === file && state.viewer === 'diff') { return false; } diff --git a/app/assets/javascripts/ide/stores/mutations/file.js b/app/assets/javascripts/ide/stores/mutations/file.js index b52d1f96e28..0f5c64076b7 100644 --- a/app/assets/javascripts/ide/stores/mutations/file.js +++ b/app/assets/javascripts/ide/stores/mutations/file.js @@ -156,7 +156,7 @@ export default { [types.ADD_PENDING_TAB](state, { file, keyPrefix = 'pending' }) { const pendingTab = state.openFiles.find(f => f.path === file.path && f.pending); let openFiles = state.openFiles.map(f => - Object.assign(f, { active: f.path === file.path, opened: false }), + Object.assign(f, { active: f.path === file.path, opened: false, active: false }), ); if (!pendingTab) { @@ -168,6 +168,7 @@ export default { if (f.path === file.path) { return acc.concat({ ...f, + content: file.content, active: true, pending: true, opened: true, |