Commit 894b6fe1 authored by Phil Hughes's avatar Phil Hughes

Fixed a bug where the index would be incorrect

parent 6783350d
...@@ -9,17 +9,19 @@ export default { ...@@ -9,17 +9,19 @@ export default {
watch: { watch: {
index: { index: {
handler() { handler() {
if (this.index < 0) return; const { index } = this;
if (this.vscrollParent.itemsWithSize[this.index].size) { if (index < 0) return;
this.scrollToIndex();
if (this.vscrollParent.itemsWithSize[index].size) {
this.scrollToIndex(index);
} else { } else {
this.$_itemsWithSizeWatcher = this.$watch('vscrollParent.itemsWithSize', async () => { this.$_itemsWithSizeWatcher = this.$watch('vscrollParent.itemsWithSize', async () => {
await this.$nextTick(); await this.$nextTick();
if (this.vscrollParent.itemsWithSize[this.index].size) { if (this.vscrollParent.itemsWithSize[index].size) {
this.$_itemsWithSizeWatcher(); this.$_itemsWithSizeWatcher();
this.scrollToIndex(); this.scrollToIndex(index);
} }
}); });
} }
...@@ -31,8 +33,8 @@ export default { ...@@ -31,8 +33,8 @@ export default {
if (this.$_itemsWithSizeWatcher) this.$_itemsWithSizeWatcher(); if (this.$_itemsWithSizeWatcher) this.$_itemsWithSizeWatcher();
}, },
methods: { methods: {
scrollToIndex() { scrollToIndex(index) {
this.vscrollParent.scrollToItem(this.index); this.vscrollParent.scrollToItem(index);
}, },
}, },
render(h) { render(h) {
......
...@@ -125,6 +125,11 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { ...@@ -125,6 +125,11 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
commit(types.SET_DIFF_DATA_BATCH, { diff_files }); commit(types.SET_DIFF_DATA_BATCH, { diff_files });
commit(types.SET_BATCH_LOADING, false); commit(types.SET_BATCH_LOADING, false);
eventHub.$emit(
'scrollToFileHash',
window.location.hash.replace('#', '').split('diff-content-').pop(),
);
if (!isNoteLink && !state.currentDiffFileId) { if (!isNoteLink && !state.currentDiffFileId) {
commit(types.VIEW_DIFF_FILE, diff_files[0].file_hash); commit(types.VIEW_DIFF_FILE, diff_files[0].file_hash);
} }
...@@ -190,12 +195,6 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => { ...@@ -190,12 +195,6 @@ export const fetchDiffFilesBatch = ({ commit, state, dispatch }) => {
return getBatch() return getBatch()
.then(() => !window.gon?.features?.diffsVirtualScrolling && handleLocationHash()) .then(() => !window.gon?.features?.diffsVirtualScrolling && handleLocationHash())
.then(() => {
eventHub.$emit(
'scrollToFileHash',
window.location.hash.replace('#', '').split('diff-content-').pop(),
);
})
.catch(() => null); .catch(() => null);
}; };
......
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