fixed opening next tab being a pending tab

clears any active files when opening pending tab
This commit is contained in:
Phil Hughes 2018-03-23 09:03:45 +00:00
parent c439548830
commit 5dbb7a2519
No known key found for this signature in database
GPG key ID: 32245528C52E0F9F
2 changed files with 33 additions and 12 deletions

View file

@ -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}/`);
};

View file

@ -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, {