summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-03-23 09:03:45 +0000
committerPhil Hughes <me@iamphill.com>2018-03-28 14:08:30 +0100
commit5dbb7a2519d6eaed634aeee6c78502941ff527fb (patch)
treefb6119725148c60ea4cfeba21829e377b92434cf
parentc439548830c523e961797820c3ad1221485ebc61 (diff)
downloadgitlab-ce-5dbb7a2519d6eaed634aeee6c78502941ff527fb.tar.gz
fixed opening next tab being a pending tab
clears any active files when opening pending tab
-rw-r--r--app/assets/javascripts/ide/stores/actions/file.js14
-rw-r--r--app/assets/javascripts/ide/stores/mutations/file.js31
2 files changed, 33 insertions, 12 deletions
diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js
index dbb42154ec5..8c41782cfb2 100644
--- a/app/assets/javascripts/ide/stores/actions/file.js
+++ b/app/assets/javascripts/ide/stores/actions/file.js
@@ -12,7 +12,7 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
if (file.pending) {
commit(types.REMOVE_PENDING_TAB, file);
} else {
- const indexOfClosedFile = state.openFiles.findIndex(f => f.path === path);
+ const indexOfClosedFile = getters.tabs.findIndex(f => f.path === path);
const fileWasActive = file.active;
commit(types.TOGGLE_FILE_OPEN, path);
@@ -21,9 +21,13 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
if (getters.tabs.length > 0 && fileWasActive) {
const nextIndexToOpen =
indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1;
- const nextFileToOpen = state.openFiles[nextIndexToOpen];
+ const nextFileToOpen = getters.tabs[nextIndexToOpen];
- router.push(`/project${nextFileToOpen.url}`);
+ if (nextFileToOpen.pending) {
+ dispatch('openPendingTab', nextFileToOpen);
+ } else {
+ router.push(`/project${nextFileToOpen.url}`);
+ }
} else if (!state.openFiles.length) {
router.push(`/project/${file.projectId}/tree/${file.branchId}/`);
}
@@ -151,9 +155,11 @@ export const discardFileChanges = ({ state, commit }, path) => {
eventHub.$emit(`editor.update.model.content.${file.path}`, file.raw);
};
-export const openPendingTab = ({ commit, state }, file) => {
+export const openPendingTab = ({ commit, dispatch, state }, file) => {
commit(types.ADD_PENDING_TAB, file);
+ dispatch('scrollToTab');
+
router.push(`/project/${file.projectId}/tree/${state.currentBranchId}/`);
};
diff --git a/app/assets/javascripts/ide/stores/mutations/file.js b/app/assets/javascripts/ide/stores/mutations/file.js
index 06fd55bfa83..65ea1e46b58 100644
--- a/app/assets/javascripts/ide/stores/mutations/file.js
+++ b/app/assets/javascripts/ide/stores/mutations/file.js
@@ -88,14 +88,29 @@ export default {
});
},
[types.ADD_PENDING_TAB](state, file) {
- Object.assign(state, {
- pendingTabs: state.pendingTabs.concat({
- ...file,
- active: true,
- pending: true,
- key: `pending-${file.key}`,
- }),
- });
+ const pendingTab = state.pendingTabs.find(f => f.path === file.path);
+
+ if (pendingTab) {
+ Object.assign(state, {
+ pendingTabs: state.pendingTabs.map(tab => ({
+ ...tab,
+ active: !!pendingTab,
+ })),
+ });
+ } else {
+ Object.assign(state, {
+ pendingTabs: state.pendingTabs.concat({
+ ...file,
+ active: true,
+ pending: true,
+ key: `pending-${file.key}`,
+ }),
+ openFiles: state.openFiles.map(f => ({
+ ...f,
+ active: false,
+ })),
+ });
+ }
},
[types.REMOVE_PENDING_TAB](state, file) {
Object.assign(state, {