未验证 提交 5dbb7a25 编写于 作者: P Phil Hughes

fixed opening next tab being a pending tab

clears any active files when opening pending tab
上级 c4395488
......@@ -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}/`);
};
......
......@@ -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, {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册