opens the next open tab correctly

fixes model being cached as undefined
fixed open files not being correctly mutated
This commit is contained in:
Phil Hughes 2018-03-23 11:16:42 +00:00
parent 5dbb7a2519
commit c5c7baec60
No known key found for this signature in database
GPG Key ID: 32245528C52E0F9F
6 changed files with 96 additions and 71 deletions

View File

@ -36,7 +36,7 @@ export default {
this.editor.updateDimensions();
},
viewer() {
// this.createEditorInstance();
this.createEditorInstance();
},
},
beforeDestroy() {

View File

@ -23,7 +23,7 @@ export default class ModelManager {
}
const model = new Model(this.monaco, file);
this.models.set(model.key, model);
this.models.set(model.path, model);
this.disposable.add(model);
eventHub.$on(

View File

@ -44,7 +44,7 @@ export default class DirtyDiffController {
computeDiff(model) {
this.dirtyDiffWorker.postMessage({
key: model.key,
key: model.path,
originalContent: model.getOriginalModel().getValue(),
newContent: model.getModel().getValue(),
});

View File

@ -8,29 +8,29 @@ import { setPageTitle } from '../utils';
export const closeFile = ({ commit, state, getters, dispatch }, file) => {
const path = file.path;
const indexOfClosedFile = getters.tabs.findIndex(f => f.key === file.key);
const fileWasActive = file.active;
if (file.pending) {
commit(types.REMOVE_PENDING_TAB, file);
} else {
const indexOfClosedFile = getters.tabs.findIndex(f => f.path === path);
const fileWasActive = file.active;
commit(types.TOGGLE_FILE_OPEN, path);
commit(types.SET_FILE_ACTIVE, { path, active: false });
}
if (getters.tabs.length > 0 && fileWasActive) {
const nextIndexToOpen =
indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1;
const nextFileToOpen = getters.tabs[nextIndexToOpen];
if (getters.tabs.length > 0 && fileWasActive) {
const nextIndexToOpen = indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1;
const nextFileToOpen = getters.tabs[nextIndexToOpen];
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}/`);
if (nextFileToOpen.pending) {
dispatch('updateViewer', 'diff');
dispatch('openPendingTab', nextFileToOpen);
} else {
dispatch('updateDelayViewerUpdated', true);
router.push(`/project${nextFileToOpen.url}`);
}
} else if (!getters.tabs.length) {
router.push(`/project/${file.projectId}/tree/${file.branchId}/`);
}
eventHub.$emit(`editor.update.model.dispose.${file.key}`);

View File

@ -2,9 +2,7 @@ import { normalizeHeaders } from '~/lib/utils/common_utils';
import flash from '~/flash';
import service from '../../services';
import * as types from '../mutation_types';
import {
findEntry,
} from '../utils';
import { findEntry } from '../utils';
import FilesDecoratorWorker from '../workers/files_decorator_worker';
export const toggleTreeOpen = ({ commit, dispatch }, path) => {
@ -25,20 +23,29 @@ export const handleTreeEntryAction = ({ commit, dispatch }, row) => {
}
};
export const getLastCommitData = ({ state, commit, dispatch, getters }, tree = state) => {
export const getLastCommitData = (
{ state, commit, dispatch, getters },
tree = state,
) => {
if (!tree || tree.lastCommitPath === null || !tree.lastCommitPath) return;
service.getTreeLastCommit(tree.lastCommitPath)
.then((res) => {
const lastCommitPath = normalizeHeaders(res.headers)['MORE-LOGS-URL'] || null;
service
.getTreeLastCommit(tree.lastCommitPath)
.then(res => {
const lastCommitPath =
normalizeHeaders(res.headers)['MORE-LOGS-URL'] || null;
commit(types.SET_LAST_COMMIT_URL, { tree, url: lastCommitPath });
return res.json();
})
.then((data) => {
data.forEach((lastCommit) => {
const entry = findEntry(tree.tree, lastCommit.type, lastCommit.file_name);
.then(data => {
data.forEach(lastCommit => {
const entry = findEntry(
tree.tree,
lastCommit.type,
lastCommit.file_name,
);
if (entry) {
commit(types.SET_LAST_COMMIT_DATA, { entry, lastCommit });
@ -47,47 +54,62 @@ export const getLastCommitData = ({ state, commit, dispatch, getters }, tree = s
dispatch('getLastCommitData', tree);
})
.catch(() => flash('Error fetching log data.', 'alert', document, null, false, true));
.catch(() =>
flash('Error fetching log data.', 'alert', document, null, false, true),
);
};
export const getFiles = (
{ state, commit, dispatch },
{ projectId, branchId } = {},
) => new Promise((resolve, reject) => {
if (!state.trees[`${projectId}/${branchId}`]) {
const selectedProject = state.projects[projectId];
commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` });
) =>
new Promise((resolve, reject) => {
if (!state.trees[`${projectId}/${branchId}`]) {
const selectedProject = state.projects[projectId];
commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` });
service
.getFiles(selectedProject.web_url, branchId)
.then(res => res.json())
.then((data) => {
const worker = new FilesDecoratorWorker();
worker.addEventListener('message', (e) => {
const { entries, treeList } = e.data;
const selectedTree = state.trees[`${projectId}/${branchId}`];
service
.getFiles(selectedProject.web_url, branchId)
.then(res => res.json())
.then(data => {
const worker = new FilesDecoratorWorker();
worker.addEventListener('message', e => {
const { entries, treeList } = e.data;
const selectedTree = state.trees[`${projectId}/${branchId}`];
commit(types.SET_ENTRIES, entries);
commit(types.SET_DIRECTORY_DATA, { treePath: `${projectId}/${branchId}`, data: treeList });
commit(types.TOGGLE_LOADING, { entry: selectedTree, forceValue: false });
commit(types.SET_ENTRIES, entries);
commit(types.SET_DIRECTORY_DATA, {
treePath: `${projectId}/${branchId}`,
data: treeList,
});
commit(types.TOGGLE_LOADING, {
entry: selectedTree,
forceValue: false,
});
worker.terminate();
worker.terminate();
resolve();
resolve();
});
worker.postMessage({
data,
projectId,
branchId,
});
})
.catch(e => {
flash(
'Error loading tree data. Please try again.',
'alert',
document,
null,
false,
true,
);
reject(e);
});
worker.postMessage({
data,
projectId,
branchId,
});
})
.catch((e) => {
flash('Error loading tree data. Please try again.', 'alert', document, null, false, true);
reject(e);
});
} else {
resolve();
}
});
} else {
resolve();
}
});

View File

@ -6,12 +6,14 @@ export default {
active,
});
Object.assign(state, {
pendingTabs: state.pendingTabs.map(f => ({
...f,
active: false,
})),
});
if (active) {
Object.assign(state, {
pendingTabs: state.pendingTabs.map(f => ({
...f,
active: false,
})),
});
}
},
[types.TOGGLE_FILE_OPEN](state, path) {
Object.assign(state.entries[path], {
@ -105,10 +107,11 @@ export default {
pending: true,
key: `pending-${file.key}`,
}),
openFiles: state.openFiles.map(f => ({
...f,
active: false,
})),
openFiles: state.openFiles.map(f =>
Object.assign(f, {
active: false,
}),
),
});
}
},