Skip to content

Commit a0eacfa

Browse files
author
Guillaume Chau
committed
fix: scroll to inspected item
1 parent c9cb98f commit a0eacfa

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

packages/app-frontend/src/mixins/entry-list.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,39 @@ export default function ({
1818
},
1919

2020
methods: {
21-
refreshScrollToInspected: debounce(function () {
22-
requestAnimationFrame(() => {
23-
if (this.inspectedIndex) this.scrollIntoInspected(this.inspectedIndex)
24-
})
25-
}, 200, {
26-
leading: true
27-
}),
21+
refreshScrollToInspected () {
22+
if (this.inspectedIndex) this.scrollIntoInspected(this.inspectedIndex)
23+
},
2824

29-
scrollIntoInspected: debounce(function (index) {
25+
scrollIntoInspected: debounce(async function (index) {
3026
index += indexOffset
31-
this.$nextTick(() => {
32-
const scroller = this.$globalRefs.leftRecycleList || this.$globalRefs.leftScroll
33-
if (!scroller) {
34-
this.scrollIntoInspected(index)
35-
return
36-
}
37-
const parentHeight = scroller.offsetHeight
38-
const height = this.highDensity ? 22 : 34
39-
const top = index * height
40-
const scrollTop = scroller.scrollTop
41-
if (top < scrollTop) {
42-
scroller.scrollTop = top
43-
} else if (top + height > scrollTop + parentHeight) {
44-
scroller.scrollTop = top + height - parentHeight
45-
}
46-
})
27+
// Wait for defer frames (time-slicing)
28+
for (let f = 0; f < 2; f++) {
29+
await waitForFrame()
30+
}
31+
const scroller = this.$globalRefs.leftRecycleList || this.$globalRefs.leftScroll
32+
if (!scroller) {
33+
this.scrollIntoInspected(index)
34+
return
35+
}
36+
const parentHeight = scroller.offsetHeight
37+
const height = this.highDensity ? 22 : 34
38+
const top = index * height
39+
const scrollTop = scroller.scrollTop
40+
if (top < scrollTop) {
41+
scroller.scrollTop = top
42+
} else if (top + height > scrollTop + parentHeight) {
43+
scroller.scrollTop = top + height - parentHeight
44+
}
4745
}, 200, {
4846
leading: true
4947
})
5048
}
5149
}
5250
}
51+
52+
function waitForFrame () {
53+
return new Promise(resolve => {
54+
requestAnimationFrame(resolve)
55+
})
56+
}

0 commit comments

Comments
 (0)