mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-12 03:42:08 +00:00
fix(tui): refresh scroll height at cached bottom
This commit is contained in:
parent
5b24c0fa85
commit
2c14d3b9b0
2 changed files with 63 additions and 3 deletions
|
|
@ -3,9 +3,12 @@ import { describe, expect, it, vi } from 'vitest'
|
|||
import { scrollWithSelectionBy } from '../app/scroll.js'
|
||||
|
||||
function makeScroll(overrides: Partial<Record<string, unknown>> = {}) {
|
||||
const getScrollHeight = (overrides.getScrollHeight as (() => number) | undefined) ?? vi.fn(() => 100)
|
||||
|
||||
return {
|
||||
getFreshScrollHeight: vi.fn(() => getScrollHeight()),
|
||||
getPendingDelta: vi.fn(() => 0),
|
||||
getScrollHeight: vi.fn(() => 100),
|
||||
getScrollHeight,
|
||||
getScrollTop: vi.fn(() => 10),
|
||||
getViewportHeight: vi.fn(() => 20),
|
||||
getViewportTop: vi.fn(() => 0),
|
||||
|
|
@ -34,6 +37,47 @@ describe('scrollWithSelectionBy', () => {
|
|||
expect(s.scrollBy).toHaveBeenCalledWith(1)
|
||||
})
|
||||
|
||||
it('uses fresh scroll height when cached height would swallow a down-scroll at a fake bottom', () => {
|
||||
const s = makeScroll({
|
||||
getFreshScrollHeight: vi.fn(() => 34),
|
||||
getScrollHeight: vi.fn(() => 30),
|
||||
getScrollTop: vi.fn(() => 10),
|
||||
getViewportHeight: vi.fn(() => 20)
|
||||
})
|
||||
|
||||
const selection = {
|
||||
captureScrolledRows: vi.fn(),
|
||||
getState: vi.fn(() => null),
|
||||
shiftAnchor: vi.fn(),
|
||||
shiftSelection: vi.fn()
|
||||
}
|
||||
|
||||
scrollWithSelectionBy(10, { scrollRef: { current: s as never }, selection })
|
||||
|
||||
expect(s.scrollBy).toHaveBeenCalledWith(4)
|
||||
})
|
||||
|
||||
it('uses fresh height when pending down-scroll reaches the cached fake bottom', () => {
|
||||
const s = makeScroll({
|
||||
getFreshScrollHeight: vi.fn(() => 38),
|
||||
getPendingDelta: vi.fn(() => 2),
|
||||
getScrollHeight: vi.fn(() => 32),
|
||||
getScrollTop: vi.fn(() => 10),
|
||||
getViewportHeight: vi.fn(() => 20)
|
||||
})
|
||||
|
||||
const selection = {
|
||||
captureScrolledRows: vi.fn(),
|
||||
getState: vi.fn(() => null),
|
||||
shiftAnchor: vi.fn(),
|
||||
shiftSelection: vi.fn()
|
||||
}
|
||||
|
||||
scrollWithSelectionBy(10, { scrollRef: { current: s as never }, selection })
|
||||
|
||||
expect(s.scrollBy).toHaveBeenCalledWith(6)
|
||||
})
|
||||
|
||||
it('does nothing at the edge instead of queueing dead pending deltas', () => {
|
||||
const s = makeScroll({
|
||||
getScrollHeight: vi.fn(() => 30),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue