Commit 5dbb7a25 authored by Phil Hughes's avatar Phil Hughes

fixed opening next tab being a pending tab

clears any active files when opening pending tab
parent c4395488
...@@ -12,7 +12,7 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => { ...@@ -12,7 +12,7 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
if (file.pending) { if (file.pending) {
commit(types.REMOVE_PENDING_TAB, file); commit(types.REMOVE_PENDING_TAB, file);
} else { } else {
const indexOfClosedFile = state.openFiles.findIndex(f => f.path === path); const indexOfClosedFile = getters.tabs.findIndex(f => f.path === path);
const fileWasActive = file.active; const fileWasActive = file.active;
commit(types.TOGGLE_FILE_OPEN, path); commit(types.TOGGLE_FILE_OPEN, path);
...@@ -21,9 +21,13 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => { ...@@ -21,9 +21,13 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
if (getters.tabs.length > 0 && fileWasActive) { if (getters.tabs.length > 0 && fileWasActive) {
const nextIndexToOpen = const nextIndexToOpen =
indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1; indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1;
const nextFileToOpen = state.openFiles[nextIndexToOpen]; const nextFileToOpen = getters.tabs[nextIndexToOpen];
if (nextFileToOpen.pending) {
dispatch('openPendingTab', nextFileToOpen);
} else {
router.push(`/project${nextFileToOpen.url}`); router.push(`/project${nextFileToOpen.url}`);
}
} else if (!state.openFiles.length) { } else if (!state.openFiles.length) {
router.push(`/project/${file.projectId}/tree/${file.branchId}/`); router.push(`/project/${file.projectId}/tree/${file.branchId}/`);
} }
...@@ -151,9 +155,11 @@ export const discardFileChanges = ({ state, commit }, path) => { ...@@ -151,9 +155,11 @@ export const discardFileChanges = ({ state, commit }, path) => {
eventHub.$emit(`editor.update.model.content.${file.path}`, file.raw); 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); commit(types.ADD_PENDING_TAB, file);
dispatch('scrollToTab');
router.push(`/project/${file.projectId}/tree/${state.currentBranchId}/`); router.push(`/project/${file.projectId}/tree/${state.currentBranchId}/`);
}; };
......
...@@ -88,6 +88,16 @@ export default { ...@@ -88,6 +88,16 @@ export default {
}); });
}, },
[types.ADD_PENDING_TAB](state, file) { [types.ADD_PENDING_TAB](state, file) {
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, { Object.assign(state, {
pendingTabs: state.pendingTabs.concat({ pendingTabs: state.pendingTabs.concat({
...file, ...file,
...@@ -95,7 +105,12 @@ export default { ...@@ -95,7 +105,12 @@ export default {
pending: true, pending: true,
key: `pending-${file.key}`, key: `pending-${file.key}`,
}), }),
openFiles: state.openFiles.map(f => ({
...f,
active: false,
})),
}); });
}
}, },
[types.REMOVE_PENDING_TAB](state, file) { [types.REMOVE_PENDING_TAB](state, file) {
Object.assign(state, { Object.assign(state, {
......
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