Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/diffs/components/virtual_scroller_scroll_sync.js')
-rw-r--r--app/assets/javascripts/diffs/components/virtual_scroller_scroll_sync.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/app/assets/javascripts/diffs/components/virtual_scroller_scroll_sync.js b/app/assets/javascripts/diffs/components/virtual_scroller_scroll_sync.js
new file mode 100644
index 00000000000..984c6f8c0c9
--- /dev/null
+++ b/app/assets/javascripts/diffs/components/virtual_scroller_scroll_sync.js
@@ -0,0 +1,51 @@
+import { handleLocationHash } from '~/lib/utils/common_utils';
+
+export default {
+ inject: ['vscrollParent'],
+ props: {
+ index: {
+ type: Number,
+ required: true,
+ },
+ },
+ watch: {
+ index: {
+ handler() {
+ const { index } = this;
+
+ if (index < 0) return;
+
+ if (this.vscrollParent.itemsWithSize[index].size) {
+ this.scrollToIndex(index);
+ } else {
+ this.$_itemsWithSizeWatcher = this.$watch('vscrollParent.itemsWithSize', async () => {
+ await this.$nextTick();
+
+ if (this.vscrollParent.itemsWithSize[index].size) {
+ this.$_itemsWithSizeWatcher();
+ this.scrollToIndex(index);
+
+ await this.$nextTick();
+ }
+ });
+ }
+ },
+ immediate: true,
+ },
+ },
+ beforeDestroy() {
+ if (this.$_itemsWithSizeWatcher) this.$_itemsWithSizeWatcher();
+ },
+ methods: {
+ scrollToIndex(index) {
+ this.vscrollParent.scrollToItem(index);
+
+ setTimeout(() => {
+ handleLocationHash();
+ });
+ },
+ },
+ render(h) {
+ return h(null);
+ },
+};