fix(tui): steady scrollbar after transcript shrink
(cherry picked from commit 40b0e93b12622679a34571fba04e13a27eec8e55)
This commit is contained in:
@@ -87,4 +87,22 @@ describe('viewportStore', () => {
|
||||
|
||||
expect(getScrollbarSnapshot(handle as any).top).toBe(10)
|
||||
})
|
||||
|
||||
it('uses fresh scroll height to clear stale scrollbar non-bottom state after shrink', () => {
|
||||
const handle = {
|
||||
getFreshScrollHeight: () => 40,
|
||||
getScrollHeight: () => 60,
|
||||
getScrollTop: () => 20,
|
||||
getViewportHeight: () => 20
|
||||
}
|
||||
|
||||
const snap = getScrollbarSnapshot(handle as any)
|
||||
|
||||
expect(snap).toEqual({
|
||||
scrollHeight: 40,
|
||||
top: 20,
|
||||
viewportHeight: 20
|
||||
})
|
||||
expect(scrollbarSnapshotKey(snap)).toBe('20:20:40')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -70,12 +70,24 @@ export function getScrollbarSnapshot(s?: ScrollBoxHandle | null): ScrollbarSnaps
|
||||
}
|
||||
|
||||
const viewportHeight = Math.max(0, s.getViewportHeight())
|
||||
const scrollHeight = Math.max(viewportHeight, s.getScrollHeight())
|
||||
const maxTop = Math.max(0, scrollHeight - viewportHeight)
|
||||
const top = Math.max(0, s.getScrollTop())
|
||||
const cachedScrollHeight = Math.max(viewportHeight, s.getScrollHeight())
|
||||
let scrollHeight = cachedScrollHeight
|
||||
let maxTop = Math.max(0, scrollHeight - viewportHeight)
|
||||
|
||||
if (top < maxTop) {
|
||||
const freshScrollHeight = Math.max(viewportHeight, s.getFreshScrollHeight?.() ?? cachedScrollHeight)
|
||||
const freshMaxTop = Math.max(0, freshScrollHeight - viewportHeight)
|
||||
|
||||
if (top >= freshMaxTop) {
|
||||
scrollHeight = freshScrollHeight
|
||||
maxTop = freshMaxTop
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
scrollHeight,
|
||||
top: Math.max(0, Math.min(maxTop, s.getScrollTop())),
|
||||
top: Math.max(0, Math.min(maxTop, top)),
|
||||
viewportHeight
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user