mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-21 18:26:09 +00:00
+22






![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)

![opencode-agent[bot]](/assets/img/avatar_default.png)
opencode-agent[bot]
GitHub
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Aiden Cline
usrnk1
Aarav Sareen
Luke Parker
Brendan Allan
Kit Langton
James Long
Adam
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
Jay
Simon Klee
Jay
Jack
David Hill
Brendan Allan
opencode
Aiden Cline
James Long
Dustin Deus
冯基魁
Frank
Aiden Cline
Victor Navarro
Dax Raad
Dax
Nabs
Vladimir Glafirov
AidenGeunGeun
Mark
634386fe0f
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Jay <air@live.ca> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: James Long <jlongster@users.noreply.github.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: 冯基魁 <56265583+fengjikui@users.noreply.github.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com> Co-authored-by: Victor Navarro <vn4varro@gmail.com> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Nabs <nabil@instafork.com> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: AidenGeunGeun <eastlandwyvern@gmail.com> Co-authored-by: Mark <geraint0923@users.noreply.github.com>
113 lines
3.8 KiB
TypeScript
113 lines
3.8 KiB
TypeScript
import { expect, test } from "bun:test"
|
|
import { createVirtualizer, defaultRangeExtractor, Virtualizer } from "@tanstack/solid-virtual"
|
|
import { createRoot, createSignal } from "solid-js"
|
|
import { filterVirtualIndexes } from "@/pages/session/timeline/virtual-items"
|
|
|
|
test("end anchoring survives consecutive resizes when the first scroll write is clamped", () => {
|
|
const writes: { offset: number; adjustments?: number }[] = []
|
|
const virtualizer = new Virtualizer<HTMLDivElement, HTMLDivElement>({
|
|
count: 5,
|
|
estimateSize: () => 50,
|
|
initialOffset: 50,
|
|
initialRect: { width: 400, height: 200 },
|
|
anchorTo: "end",
|
|
scrollEndThreshold: 1,
|
|
getScrollElement: () => null,
|
|
scrollToFn: (offset, options) => writes.push({ offset, adjustments: options.adjustments }),
|
|
observeElementRect: () => {},
|
|
observeElementOffset: () => {},
|
|
})
|
|
|
|
virtualizer.getTotalSize()
|
|
virtualizer.resizeItem(4, 120)
|
|
expect(writes).toEqual([{ offset: 50, adjustments: 70 }])
|
|
writes.length = 0
|
|
|
|
virtualizer.resizeItem(4, 200)
|
|
expect(writes).toEqual([{ offset: 120, adjustments: 80 }])
|
|
})
|
|
|
|
test("reactive count updates preserve measured row sizes", () => {
|
|
createRoot((dispose) => {
|
|
const [count, setCount] = createSignal(2)
|
|
const virtualizer = createVirtualizer<HTMLDivElement, HTMLDivElement>({
|
|
get count() {
|
|
return count()
|
|
},
|
|
getScrollElement: () => null,
|
|
estimateSize: () => 60,
|
|
initialRect: { width: 800, height: 600 },
|
|
})
|
|
|
|
expect(virtualizer.getTotalSize()).toBe(120)
|
|
virtualizer.resizeItem(0, 100)
|
|
expect(virtualizer.getTotalSize()).toBe(160)
|
|
|
|
setCount(3)
|
|
|
|
expect(virtualizer.itemSizeCache.get(0)).toBe(100)
|
|
expect(virtualizer.getTotalSize()).toBe(220)
|
|
dispose()
|
|
})
|
|
})
|
|
|
|
test("initial rect projects rows before a scroll element connects", () => {
|
|
createRoot((dispose) => {
|
|
const virtualizer = createVirtualizer<HTMLDivElement, HTMLDivElement>({
|
|
count: 100,
|
|
getScrollElement: () => null,
|
|
estimateSize: () => 28,
|
|
initialRect: { width: 0, height: 600 },
|
|
overscan: 10,
|
|
})
|
|
|
|
expect(virtualizer.getVirtualItems().length).toBeGreaterThan(0)
|
|
dispose()
|
|
})
|
|
})
|
|
|
|
test("clamps oversized offsets with scroll margin and padding changes", () => {
|
|
const options = (paddingEnd: number) => ({
|
|
count: 20,
|
|
estimateSize: () => 60,
|
|
initialOffset: Number.MAX_SAFE_INTEGER,
|
|
initialRect: { width: 800, height: 600 },
|
|
scrollMargin: 64,
|
|
paddingEnd,
|
|
overscan: 1,
|
|
getScrollElement: () => null,
|
|
scrollToFn: () => {},
|
|
observeElementRect: () => {},
|
|
observeElementOffset: () => {},
|
|
})
|
|
const virtualizer = new Virtualizer<HTMLDivElement, HTMLDivElement>(options(64))
|
|
|
|
expect(virtualizer.getVirtualItems().map((item) => item.index)).toEqual([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
|
|
|
|
virtualizer.setOptions(options(600))
|
|
expect(virtualizer.getVirtualItems().map((item) => item.index)).toEqual([18, 19])
|
|
})
|
|
|
|
test("stale pinned indexes do not produce missing virtual items after count shrinks", () => {
|
|
createRoot((dispose) => {
|
|
const [count, setCount] = createSignal(2)
|
|
const pinned = [1]
|
|
const virtualizer = createVirtualizer<HTMLDivElement, HTMLDivElement>({
|
|
get count() {
|
|
return count()
|
|
},
|
|
getScrollElement: () => null,
|
|
estimateSize: () => 60,
|
|
initialRect: { width: 800, height: 600 },
|
|
rangeExtractor: (range) =>
|
|
filterVirtualIndexes([...new Set([...defaultRangeExtractor(range), ...pinned])], range.count),
|
|
})
|
|
|
|
expect(virtualizer.getVirtualItems().map((item) => item.index)).toEqual([0, 1])
|
|
setCount(1)
|
|
expect(virtualizer.getVirtualItems().map((item) => item.index)).toEqual([0])
|
|
expect(() => new Map(virtualizer.getVirtualItems().map((item) => [item.key, item]))).not.toThrow()
|
|
dispose()
|
|
})
|
|
})
|