fuck it, smooth scroll is unreliable
This commit is contained in:
parent
5bd9a44c2c
commit
c9d91c3d70
3 changed files with 22 additions and 14 deletions
|
|
@ -81,6 +81,7 @@ export default {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const scroller = useScrollPosition()
|
||||||
const tryScrollTo = async (id) => {
|
const tryScrollTo = async (id) => {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return
|
return
|
||||||
|
|
@ -90,14 +91,12 @@ export default {
|
||||||
}
|
}
|
||||||
setFocused(id)
|
setFocused(id)
|
||||||
const target = document.querySelector(`.Status[data-status-id=${id}]`)
|
const target = document.querySelector(`.Status[data-status-id=${id}]`)
|
||||||
await nextTick()
|
return await scroller.scrollIntoView(target, { block: 'center' })
|
||||||
return await target.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { statusId } = toRefs(props)
|
const { statusId } = toRefs(props)
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const scroller = useScrollPosition()
|
|
||||||
|
|
||||||
// # Main Configuration / global state
|
// # Main Configuration / global state
|
||||||
const { mergedConfig } = storeToRefs(useMergedConfigStore())
|
const { mergedConfig } = storeToRefs(useMergedConfigStore())
|
||||||
|
|
@ -195,11 +194,12 @@ export default {
|
||||||
// # Linear style stuff
|
// # Linear style stuff
|
||||||
const isLinearView = computed(() => displayStyle.value !== 'tree')
|
const isLinearView = computed(() => displayStyle.value !== 'tree')
|
||||||
const linearElement = useTemplateRef('linear')
|
const linearElement = useTemplateRef('linear')
|
||||||
|
const linearScrollCompensation = computed(() => isLinearView.value && isExpanded.value)
|
||||||
const {
|
const {
|
||||||
heightChart: heightChartLinear,
|
heightChart: heightChartLinear,
|
||||||
changeSuspendState: changeSuspendStateLinear,
|
changeSuspendState: changeSuspendStateLinear,
|
||||||
updateVirtualHeight: updateVirtualHeightLinear,
|
updateVirtualHeight: updateVirtualHeightLinear,
|
||||||
} = useVirtualScrolling(conversation, linearElement, scroller, true, currentStatus)
|
} = useVirtualScrolling(conversation, linearElement, scroller, linearScrollCompensation, currentStatus)
|
||||||
|
|
||||||
// # Tree style stuff
|
// # Tree style stuff
|
||||||
const isTreeView = computed(() => displayStyle.value === 'tree')
|
const isTreeView = computed(() => displayStyle.value === 'tree')
|
||||||
|
|
@ -213,11 +213,12 @@ export default {
|
||||||
provide('threadDisplay', threadDisplay)
|
provide('threadDisplay', threadDisplay)
|
||||||
|
|
||||||
const ancestorsElement = useTemplateRef('ancestors')
|
const ancestorsElement = useTemplateRef('ancestors')
|
||||||
|
const treeScrollCompensation = computed(() => isTreeView.value && isExpanded.value)
|
||||||
const {
|
const {
|
||||||
heightChart: heightChartAncestors,
|
heightChart: heightChartAncestors,
|
||||||
changeSuspendState: changeSuspendStateAncestors,
|
changeSuspendState: changeSuspendStateAncestors,
|
||||||
updateVirtualHeight: updateVirtualHeightAncestors,
|
updateVirtualHeight: updateVirtualHeightAncestors,
|
||||||
} = useVirtualScrolling(currentAncestors, ancestorsElement, scroller, true)
|
} = useVirtualScrolling(currentAncestors, ancestorsElement, scroller, treeScrollCompensation)
|
||||||
|
|
||||||
const currentLevel = computed(() => [currentStatus.value].filter(Boolean))
|
const currentLevel = computed(() => [currentStatus.value].filter(Boolean))
|
||||||
const currentLevelElement = useTemplateRef('currentLevel')
|
const currentLevelElement = useTemplateRef('currentLevel')
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { onMounted, onUnmounted, ref } from 'vue'
|
import { onMounted, onUnmounted, ref, nextTick } from 'vue'
|
||||||
|
|
||||||
export function useScrollPosition() {
|
export function useScrollPosition() {
|
||||||
const x = ref(0)
|
const x = ref(0)
|
||||||
|
|
@ -24,5 +24,11 @@ export function useScrollPosition() {
|
||||||
inProgress.value = false
|
inProgress.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
return { x, y, scrollBy, inProgress }
|
const scrollIntoView = async (element, options) => {
|
||||||
|
inProgress.value = true
|
||||||
|
await element.scrollIntoView(options)
|
||||||
|
inProgress.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return { x, y, scrollBy, scrollIntoView, inProgress }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { computed, ref, watch, nextTick } from 'vue'
|
import { computed, ref, watch, nextTick, toValue } from 'vue'
|
||||||
|
|
||||||
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
||||||
import { useStatusesStore } from 'src/stores/statuses.js'
|
import { useStatusesStore } from 'src/stores/statuses.js'
|
||||||
|
|
@ -69,7 +69,7 @@ export function useVirtualScrolling(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scrolling
|
// Scrolling
|
||||||
const { y: scrollY, inProgress: scrollInProgress } = scrollPosition
|
const { y: scrollY, inProgress: scrollInProgress, scrollBy } = scrollPosition
|
||||||
const { height: windowHeight } = useWindowSize()
|
const { height: windowHeight } = useWindowSize()
|
||||||
|
|
||||||
const topScrollBoundary = ref(0)
|
const topScrollBoundary = ref(0)
|
||||||
|
|
@ -130,8 +130,8 @@ export function useVirtualScrolling(
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(heightChart, async (newVal, oldVal) => {
|
watch(heightChart, async (newVal, oldVal) => {
|
||||||
|
if (!toValue(scrollCompensation)) return
|
||||||
if (scrollInProgress.value) return
|
if (scrollInProgress.value) return
|
||||||
if (!scrollCompensation) return
|
|
||||||
pauseWatchers()
|
pauseWatchers()
|
||||||
const getAnchoredEl = (list) => anchor.value
|
const getAnchoredEl = (list) => anchor.value
|
||||||
? list.find(({ id }) => id === anchor.value)
|
? list.find(({ id }) => id === anchor.value)
|
||||||
|
|
@ -143,10 +143,11 @@ export function useVirtualScrolling(
|
||||||
|
|
||||||
const diff = newOffset - oldOffset // Positive = down, Negative = up
|
const diff = newOffset - oldOffset // Positive = down, Negative = up
|
||||||
|
|
||||||
topScrollBoundary.value += diff
|
if (diff !== 0) {
|
||||||
bottomScrollBoundary.value += diff
|
topScrollBoundary.value += diff
|
||||||
await nextTick()
|
bottomScrollBoundary.value += diff
|
||||||
scrollPosition.scrollBy(0, diff)
|
scrollBy(0, diff)
|
||||||
|
}
|
||||||
|
|
||||||
updateBoundaries()
|
updateBoundaries()
|
||||||
resumeWatchers()
|
resumeWatchers()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue