This commit is contained in:
Henry Jameson 2026-09-10 19:10:01 +03:00
commit b7943cac84
5 changed files with 34 additions and 22 deletions

View file

@ -133,6 +133,7 @@ export default {
// # Main things // # Main things
const { const {
currentStatus, currentStatus,
mainStatus,
conversation, conversation,
replies, replies,
getReplies, getReplies,
@ -201,7 +202,7 @@ export default {
const isLinearView = computed(() => displayStyle.value !== 'tree') const isLinearView = computed(() => displayStyle.value !== 'tree')
const linearElement = useTemplateRef('linear') const linearElement = useTemplateRef('linear')
const linearScrollCompensation = computed( const linearScrollCompensation = computed(
() => isLinearView.value && isExpanded.value, () => isLinearView.value,
) )
const { const {
heightChart: heightChartLinear, heightChart: heightChartLinear,
@ -214,20 +215,11 @@ export default {
body: linearElement, body: linearElement,
scrollPositionInstance: scroller, scrollPositionInstance: scroller,
scrollCompensation: linearScrollCompensation, scrollCompensation: linearScrollCompensation,
anchorId: currentStatus.id, anchorId: mainStatus.value?.id,
anchorRepeatId: currentStatus.value?.id,
getPlaceholderHeight, getPlaceholderHeight,
}) })
watch(
expanded,
async (value) => {
pauseWatchers()
await tryScrollTo(currentStatus.value.id)
resumeWatchers()
},
{ flush: 'post' },
)
// # Tree style stuff // # Tree style stuff
const isTreeView = computed(() => displayStyle.value === 'tree') const isTreeView = computed(() => displayStyle.value === 'tree')
const { const {
@ -241,7 +233,7 @@ export default {
const ancestorsElement = useTemplateRef('ancestors') const ancestorsElement = useTemplateRef('ancestors')
const treeScrollCompensation = computed( const treeScrollCompensation = computed(
() => isTreeView.value && isExpanded.value, () => isTreeView.value,
) )
const { const {
heightChart: heightChartAncestors, heightChart: heightChartAncestors,

View file

@ -107,6 +107,8 @@
:focused="focused === element.item.id" :focused="focused === element.item.id"
conversation-rank="ancestor" conversation-rank="ancestor"
:data-status-id="element.id" :data-status-id="element.id"
:data-vs-height="element.height"
:data-vs-top="element.top"
@goto="setFocused" @goto="setFocused"
@dive="diveIntoStatus(element.item.id)" @dive="diveIntoStatus(element.item.id)"

View file

@ -22,6 +22,7 @@ export function useConversation(statusId, expanded) {
const loadError = ref(null) const loadError = ref(null)
const currentStatus = computed(() => getStatusObject(statusId.value)) const currentStatus = computed(() => getStatusObject(statusId.value))
const mainStatus = computed(() => currentStatus.value?.retweeted_status ?? currentStatus.value)
const sortById = (a, b) => { const sortById = (a, b) => {
const idA = a.type === 'retweet' ? a.retweeted_status.id : a.id const idA = a.type === 'retweet' ? a.retweeted_status.id : a.id
@ -115,6 +116,7 @@ export function useConversation(statusId, expanded) {
return { return {
currentStatus, currentStatus,
mainStatus,
conversation, conversation,
replies, replies,
getReplies, getReplies,

View file

@ -26,7 +26,7 @@ export function useTreeConversationTopology(conversation, replies, current) {
if (!result.has(id)) { if (!result.has(id)) {
result.set(id, new Set()) result.set(id, new Set())
} }
if (irid) { if (irid && conversation.value.length !== 1) {
// Setting parent for current item // Setting parent for current item
result.get(id).add(irid) result.get(id).add(irid)
} }

View file

@ -1,4 +1,4 @@
import { computed, ref, toValue, watch } from 'vue' import { computed, ref, toValue, watch, nextTick } from 'vue'
import { useWindowSize } from 'src/composables/useWindowSize.js' import { useWindowSize } from 'src/composables/useWindowSize.js'
@ -12,6 +12,7 @@ export function useVirtualScrolling({
// ID of anchor element, used for scroll compensation. // ID of anchor element, used for scroll compensation.
// Omitting it makes last element the anchor // Omitting it makes last element the anchor
anchorId, anchorId,
anchorRepeatId,
// whether to use scroll compensation when elements above anchor change // whether to use scroll compensation when elements above anchor change
scrollCompensation, scrollCompensation,
// Placeholder height specification. Must be a function. // Placeholder height specification. Must be a function.
@ -69,27 +70,41 @@ export function useVirtualScrolling({
} = scrollPositionInstance } = scrollPositionInstance
watch(heightChart, async (newVal, oldVal) => { watch(heightChart, async (newVal, oldVal) => {
if (!toValue(scrollCompensation)) return if (!toValue(scrollCompensation)) return
if (scrollInProgress.value) return if (newVal.length === 0 && oldVal.length === 0) return
pauseWatchers() pauseWatchers()
// If we're not given an achor, treat last element as one // If we're not given an achor, treat last element as one
const getAnchoredEl = (list) => const getAnchoredEl = (list) =>
anchorId?.value toValue(anchorId)
? list.find(({ id }) => id === anchorId?.value) ? list.find(({ id }) => id === toValue(anchorId) || id === toValue(anchorRepeatId))
: list[list.length - 1] : list[list.length - 1]
const oldElement = getAnchoredEl(oldVal) const oldElement = getAnchoredEl(oldVal)
const newElement = getAnchoredEl(newVal) const newElement = getAnchoredEl(newVal)
const oldOffset = oldElement?.top ?? 0
const newOffset = newElement?.top ?? 0
const diff = newOffset - oldOffset // Positive = down, Negative = up const diff = (() => {
if (oldElement && newElement) {
// Generic shifting
const oldOffset = toValue(anchorId) ? oldElement.top : (oldElement.top + oldElement.height)
const newOffset = toValue(anchorId) ? newElement.top : (newElement.top + newElement.height)
return newOffset - oldOffset
} else if (!oldElement && newElement) {
// Expansion
return newElement.top + newElement.height
} else if (oldElement && !newElement) {
// Collapsing
return 0 - oldElement.top - oldElement.height
} else {
throw new Error("Somehow both new and old elements are missing, this shouldn't happen")
}
})()
if (diff !== 0) { if (diff !== 0) {
// Scroll by amount offset changed to keep it in view // Scroll by amount offset changed to keep it in view
topScrollBoundary.value += diff topScrollBoundary.value += diff
bottomScrollBoundary.value += diff bottomScrollBoundary.value += diff
scrollBy(0, diff) await nextTick()
await scrollBy(0, diff)
} }
resumeWatchers() resumeWatchers()
@ -212,5 +227,6 @@ export function useVirtualScrolling({
updateVirtualHeight, updateVirtualHeight,
pauseWatchers, pauseWatchers,
resumeWatchers, resumeWatchers,
updateBoundaries,
} }
} }