Commit c4395488 authored by Phil Hughes's avatar Phil Hughes

fix closing & reopening pending tabs

parent e2f27393
...@@ -25,7 +25,7 @@ export default { ...@@ -25,7 +25,7 @@ export default {
}, },
watch: { watch: {
file(oldVal, newVal) { file(oldVal, newVal) {
if (newVal.path !== this.file.path) { if (newVal.key !== this.file.key) {
this.initMonaco(); this.initMonaco();
} }
}, },
...@@ -36,7 +36,7 @@ export default { ...@@ -36,7 +36,7 @@ export default {
this.editor.updateDimensions(); this.editor.updateDimensions();
}, },
viewer() { viewer() {
this.createEditorInstance(); // this.createEditorInstance();
}, },
}, },
beforeDestroy() { beforeDestroy() {
...@@ -70,7 +70,9 @@ export default { ...@@ -70,7 +70,9 @@ export default {
this.getRawFileData(this.file) this.getRawFileData(this.file)
.then(() => { .then(() => {
const viewerPromise = this.delayViewerUpdated ? this.updateViewer('editor') : Promise.resolve(); const viewerPromise = this.delayViewerUpdated
? this.updateViewer('editor')
: Promise.resolve();
return viewerPromise; return viewerPromise;
}) })
...@@ -78,8 +80,15 @@ export default { ...@@ -78,8 +80,15 @@ export default {
this.updateDelayViewerUpdated(false); this.updateDelayViewerUpdated(false);
this.createEditorInstance(); this.createEditorInstance();
}) })
.catch((err) => { .catch(err => {
flash('Error setting up monaco. Please try again.', 'alert', document, null, false, true); flash(
'Error setting up monaco. Please try again.',
'alert',
document,
null,
false,
true,
);
throw err; throw err;
}); });
}, },
...@@ -103,7 +112,7 @@ export default { ...@@ -103,7 +112,7 @@ export default {
this.editor.attachModel(this.model); this.editor.attachModel(this.model);
this.model.onChange((model) => { this.model.onChange(model => {
const { file } = model; const { file } = model;
if (file.active) { if (file.active) {
......
...@@ -63,11 +63,7 @@ export default { ...@@ -63,11 +63,7 @@ export default {
this.toggleTreeOpen(this.file.path); this.toggleTreeOpen(this.file.path);
} }
const delayPromise = this.file.changed return this.updateDelayViewerUpdated(true).then(() => {
? Promise.resolve()
: this.updateDelayViewerUpdated(true);
return delayPromise.then(() => {
router.push(`/project${this.file.url}`); router.push(`/project${this.file.url}`);
}); });
}, },
......
...@@ -35,7 +35,8 @@ export default { ...@@ -35,7 +35,8 @@ export default {
updated() { updated() {
if (!this.$refs.tabsScroller) return; if (!this.$refs.tabsScroller) return;
this.showShadow = this.$refs.tabsScroller.scrollWidth > this.$refs.tabsScroller.offsetWidth; this.showShadow =
this.$refs.tabsScroller.scrollWidth > this.$refs.tabsScroller.offsetWidth;
}, },
methods: { methods: {
...mapActions(['updateViewer', 'removePendingTab']), ...mapActions(['updateViewer', 'removePendingTab']),
...@@ -60,7 +61,7 @@ export default { ...@@ -60,7 +61,7 @@ export default {
> >
<repo-tab <repo-tab
v-for="tab in files" v-for="tab in files"
:key="`${tab.key}${tab.pending ? '-pending' : ''}`" :key="tab.key"
:tab="tab" :tab="tab"
/> />
</ul> </ul>
......
...@@ -13,12 +13,12 @@ export default class Model { ...@@ -13,12 +13,12 @@ export default class Model {
(this.originalModel = this.monaco.editor.createModel( (this.originalModel = this.monaco.editor.createModel(
this.file.raw, this.file.raw,
undefined, undefined,
new this.monaco.Uri(null, null, `original/${this.file.path}`), new this.monaco.Uri(null, null, `original/${this.file.key}`),
)), )),
(this.model = this.monaco.editor.createModel( (this.model = this.monaco.editor.createModel(
this.content, this.content,
undefined, undefined,
new this.monaco.Uri(null, null, this.file.path), new this.monaco.Uri(null, null, this.file.key),
)), )),
); );
...@@ -27,7 +27,7 @@ export default class Model { ...@@ -27,7 +27,7 @@ export default class Model {
this.updateContent = this.updateContent.bind(this); this.updateContent = this.updateContent.bind(this);
this.dispose = this.dispose.bind(this); this.dispose = this.dispose.bind(this);
eventHub.$on(`editor.update.model.dispose.${this.file.path}`, this.dispose); eventHub.$on(`editor.update.model.dispose.${this.file.key}`, this.dispose);
eventHub.$on( eventHub.$on(
`editor.update.model.content.${this.file.path}`, `editor.update.model.content.${this.file.path}`,
this.updateContent, this.updateContent,
...@@ -47,7 +47,7 @@ export default class Model { ...@@ -47,7 +47,7 @@ export default class Model {
} }
get path() { get path() {
return this.file.path; return this.file.key;
} }
getModel() { getModel() {
...@@ -64,7 +64,7 @@ export default class Model { ...@@ -64,7 +64,7 @@ export default class Model {
onChange(cb) { onChange(cb) {
this.events.set( this.events.set(
this.path, this.key,
this.disposable.add(this.model.onDidChangeContent(e => cb(this, e))), this.disposable.add(this.model.onDidChangeContent(e => cb(this, e))),
); );
} }
...@@ -78,12 +78,9 @@ export default class Model { ...@@ -78,12 +78,9 @@ export default class Model {
this.disposable.dispose(); this.disposable.dispose();
this.events.clear(); this.events.clear();
eventHub.$off(`editor.update.model.dispose.${this.file.key}`, this.dispose);
eventHub.$off( eventHub.$off(
`editor.update.model.dispose.${this.file.path}`, `editor.update.model.content.${this.file.key}`,
this.dispose,
);
eventHub.$off(
`editor.update.model.content.${this.file.path}`,
this.updateContent, this.updateContent,
); );
} }
......
...@@ -9,25 +9,25 @@ export default class ModelManager { ...@@ -9,25 +9,25 @@ export default class ModelManager {
this.models = new Map(); this.models = new Map();
} }
hasCachedModel(path) { hasCachedModel(key) {
return this.models.has(path); return this.models.has(key);
} }
getModel(path) { getModel(key) {
return this.models.get(path); return this.models.get(key);
} }
addModel(file) { addModel(file) {
if (this.hasCachedModel(file.path)) { if (this.hasCachedModel(file.key)) {
return this.getModel(file.path); return this.getModel(file.key);
} }
const model = new Model(this.monaco, file); const model = new Model(this.monaco, file);
this.models.set(model.path, model); this.models.set(model.key, model);
this.disposable.add(model); this.disposable.add(model);
eventHub.$on( eventHub.$on(
`editor.update.model.dispose.${file.path}`, `editor.update.model.dispose.${file.key}`,
this.removeCachedModel.bind(this, file), this.removeCachedModel.bind(this, file),
); );
...@@ -35,10 +35,10 @@ export default class ModelManager { ...@@ -35,10 +35,10 @@ export default class ModelManager {
} }
removeCachedModel(file) { removeCachedModel(file) {
this.models.delete(file.path); this.models.delete(file.key);
eventHub.$off( eventHub.$off(
`editor.update.model.dispose.${file.path}`, `editor.update.model.dispose.${file.key}`,
this.removeCachedModel, this.removeCachedModel,
); );
} }
......
...@@ -3,7 +3,7 @@ import { throttle } from 'underscore'; ...@@ -3,7 +3,7 @@ import { throttle } from 'underscore';
import DirtyDiffWorker from './diff_worker'; import DirtyDiffWorker from './diff_worker';
import Disposable from '../common/disposable'; import Disposable from '../common/disposable';
export const getDiffChangeType = (change) => { export const getDiffChangeType = change => {
if (change.modified) { if (change.modified) {
return 'modified'; return 'modified';
} else if (change.added) { } else if (change.added) {
...@@ -16,15 +16,12 @@ export const getDiffChangeType = (change) => { ...@@ -16,15 +16,12 @@ export const getDiffChangeType = (change) => {
}; };
export const getDecorator = change => ({ export const getDecorator = change => ({
range: new monaco.Range( range: new monaco.Range(change.lineNumber, 1, change.endLineNumber, 1),
change.lineNumber,
1,
change.endLineNumber,
1,
),
options: { options: {
isWholeLine: true, isWholeLine: true,
linesDecorationsClassName: `dirty-diff dirty-diff-${getDiffChangeType(change)}`, linesDecorationsClassName: `dirty-diff dirty-diff-${getDiffChangeType(
change,
)}`,
}, },
}); });
...@@ -47,7 +44,7 @@ export default class DirtyDiffController { ...@@ -47,7 +44,7 @@ export default class DirtyDiffController {
computeDiff(model) { computeDiff(model) {
this.dirtyDiffWorker.postMessage({ this.dirtyDiffWorker.postMessage({
path: model.path, key: model.key,
originalContent: model.getOriginalModel().getValue(), originalContent: model.getOriginalModel().getValue(),
newContent: model.getModel().getValue(), newContent: model.getModel().getValue(),
}); });
...@@ -59,7 +56,7 @@ export default class DirtyDiffController { ...@@ -59,7 +56,7 @@ export default class DirtyDiffController {
decorate({ data }) { decorate({ data }) {
const decorations = data.changes.map(change => getDecorator(change)); const decorations = data.changes.map(change => getDecorator(change));
const model = this.modelManager.getModel(data.path); const model = this.modelManager.getModel(data.key);
this.decorationsController.addDecorations(model, 'dirtyDiff', decorations); this.decorationsController.addDecorations(model, 'dirtyDiff', decorations);
} }
......
import { computeDiff } from './diff'; import { computeDiff } from './diff';
self.addEventListener('message', (e) => { self.addEventListener('message', e => {
const data = e.data; const data = e.data;
self.postMessage({ self.postMessage({
path: data.path, key: data.key,
changes: computeDiff(data.originalContent, data.newContent), changes: computeDiff(data.originalContent, data.newContent),
}); });
}); });
...@@ -19,7 +19,8 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => { ...@@ -19,7 +19,8 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
commit(types.SET_FILE_ACTIVE, { path, active: false }); commit(types.SET_FILE_ACTIVE, { path, active: false });
if (getters.tabs.length > 0 && fileWasActive) { if (getters.tabs.length > 0 && fileWasActive) {
const nextIndexToOpen = indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1; const nextIndexToOpen =
indexOfClosedFile === 0 ? 0 : indexOfClosedFile - 1;
const nextFileToOpen = state.openFiles[nextIndexToOpen]; const nextFileToOpen = state.openFiles[nextIndexToOpen];
router.push(`/project${nextFileToOpen.url}`); router.push(`/project${nextFileToOpen.url}`);
...@@ -28,7 +29,7 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => { ...@@ -28,7 +29,7 @@ export const closeFile = ({ commit, state, getters, dispatch }, file) => {
} }
} }
eventHub.$emit(`editor.update.model.dispose.${file.path}`); eventHub.$emit(`editor.update.model.dispose.${file.key}`);
}; };
export const setFileActive = ({ commit, state, getters, dispatch }, path) => { export const setFileActive = ({ commit, state, getters, dispatch }, path) => {
...@@ -71,7 +72,14 @@ export const getFileData = ({ state, commit, dispatch }, file) => { ...@@ -71,7 +72,14 @@ export const getFileData = ({ state, commit, dispatch }, file) => {
}) })
.catch(() => { .catch(() => {
commit(types.TOGGLE_LOADING, { entry: file }); commit(types.TOGGLE_LOADING, { entry: file });
flash('Error loading file data. Please try again.', 'alert', document, null, false, true); flash(
'Error loading file data. Please try again.',
'alert',
document,
null,
false,
true,
);
}); });
}; };
...@@ -82,7 +90,14 @@ export const getRawFileData = ({ commit, dispatch }, file) => ...@@ -82,7 +90,14 @@ export const getRawFileData = ({ commit, dispatch }, file) =>
commit(types.SET_FILE_RAW_DATA, { file, raw }); commit(types.SET_FILE_RAW_DATA, { file, raw });
}) })
.catch(() => .catch(() =>
flash('Error loading file content. Please try again.', 'alert', document, null, false, true), flash(
'Error loading file content. Please try again.',
'alert',
document,
null,
false,
true,
),
); );
export const changeFileContent = ({ state, commit }, { path, content }) => { export const changeFileContent = ({ state, commit }, { path, content }) => {
...@@ -110,7 +125,10 @@ export const setFileEOL = ({ getters, commit }, { eol }) => { ...@@ -110,7 +125,10 @@ export const setFileEOL = ({ getters, commit }, { eol }) => {
} }
}; };
export const setEditorPosition = ({ getters, commit }, { editorRow, editorColumn }) => { export const setEditorPosition = (
{ getters, commit },
{ editorRow, editorColumn },
) => {
if (getters.activeFile) { if (getters.activeFile) {
commit(types.SET_FILE_POSITION, { commit(types.SET_FILE_POSITION, {
file: getters.activeFile, file: getters.activeFile,
...@@ -141,4 +159,6 @@ export const openPendingTab = ({ commit, state }, file) => { ...@@ -141,4 +159,6 @@ export const openPendingTab = ({ commit, state }, file) => {
export const removePendingTab = ({ commit }, file) => { export const removePendingTab = ({ commit }, file) => {
commit(types.REMOVE_PENDING_TAB, file); commit(types.REMOVE_PENDING_TAB, file);
eventHub.$emit(`editor.update.model.dispose.${file.key}`);
}; };
...@@ -93,6 +93,7 @@ export default { ...@@ -93,6 +93,7 @@ export default {
...file, ...file,
active: true, active: true,
pending: true, pending: true,
key: `pending-${file.key}`,
}), }),
}); });
}, },
......
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