mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-13 03:52:00 +00:00
refactor(tui): clean thinking and viewport helpers
This commit is contained in:
parent
a30ffbe1d4
commit
7b5b524fc7
2 changed files with 15 additions and 40 deletions
|
|
@ -45,19 +45,6 @@ export function viewportSnapshotKey(v: ViewportSnapshot) {
|
|||
return `${v.atBottom ? 1 : 0}:${v.top}:${v.viewportHeight}:${v.scrollHeight}:${v.pending}`
|
||||
}
|
||||
|
||||
const snapshotFromKey = (key: string): ViewportSnapshot => {
|
||||
const [atBottom = '1', top = '0', viewportHeight = '0', scrollHeight = '0', pending = '0'] = key.split(':')
|
||||
|
||||
return {
|
||||
atBottom: atBottom === '1',
|
||||
bottom: Number(top) + Number(viewportHeight),
|
||||
pending: Number(pending),
|
||||
scrollHeight: Number(scrollHeight),
|
||||
top: Number(top),
|
||||
viewportHeight: Number(viewportHeight)
|
||||
}
|
||||
}
|
||||
|
||||
export function useViewportSnapshot(scrollRef: RefObject<ScrollBoxHandle | null>): ViewportSnapshot {
|
||||
const key = useSyncExternalStore(
|
||||
useCallback((cb: () => void) => scrollRef.current?.subscribe(cb) ?? (() => {}), [scrollRef]),
|
||||
|
|
@ -65,5 +52,16 @@ export function useViewportSnapshot(scrollRef: RefObject<ScrollBoxHandle | null>
|
|||
() => viewportSnapshotKey(EMPTY)
|
||||
)
|
||||
|
||||
return useMemo(() => snapshotFromKey(key), [key])
|
||||
return useMemo(() => {
|
||||
const [atBottom = '1', top = '0', viewportHeight = '0', scrollHeight = '0', pending = '0'] = key.split(':')
|
||||
|
||||
return {
|
||||
atBottom: atBottom === '1',
|
||||
bottom: Number(top) + Number(viewportHeight),
|
||||
pending: Number(pending),
|
||||
scrollHeight: Number(scrollHeight),
|
||||
top: Number(top),
|
||||
viewportHeight: Number(viewportHeight)
|
||||
}
|
||||
}, [key])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue