Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
- Keep what `ui.SidebarShell`'s sidebar, footer, headers and content hold and `ui.NavHeader`'s buttons clear of the left and right safe area, as on an iPhone in landscape, without padding a page inside the shell twice, and drop the gallery's own padding for it (#835 by @houko).
- Have `nsgotest` count a press of another view as a new click on the macOS and Linux targets, as headless, so a press on a page that a press just pushed or popped reaches it instead of going to the page's previous view as a double click's second (#854 by @houko).
- Free a removed view that was laid out on its own as a relayout boundary instead of the queue of boundaries keeping it, and through it the whole subtree it was in, until a later queue as long reused its slot (#1007 by @iFwu).
- Land a `List`'s scroll to a row, or to its end, where it asks when rows were inserted, removed or measured above the viewport in the same update, instead of shifted by the scroll that would have kept the visible rows in place (#1019 by @iFwu).

## [0.2.0] - 2026-11-19

Expand Down
3 changes: 2 additions & 1 deletion core/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,8 @@ func (t *Tree) updateList(v *node) bool {
p.at, p.animating = offset, cmd.animated
st.pin = &p
}
retarget = nil
// The jump sets the offset outright: the anchoring scroll this update's changes asked for is already in it.
retarget, anchor = nil, 0
if !cmd.animated {
st.jump(offset)
}
Expand Down
29 changes: 29 additions & 0 deletions core/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ func TestKeyedListKeepsTheVisibleRowsInPlace(t *testing.T) {
}
}

// A jump to a row the same batch inserts above the viewport lands on that row, animated or not: the jump replaces the offset the inserted row would have kept.
func TestKeyedListJumpsToARowInsertedAboveTheViewport(t *testing.T) {
for _, animated := range []bool{false, true} {
var ids *core.Signal[[]int]
ref := &core.Ref{}
a := nsgotest.Start(t, func(cx *core.Scope) core.Node {
ids = core.NewSignalFunc(cx, makeIDs(100, 0), nil)
return core.List{TestID: "list", Ref: ref, Style: core.Style{Height: core.Pt(400)},
Count: func() int { return len(ids.Get()) }, Key: func(i int) any { return ids.Get()[i] },
EstimatedSize: 40, Row: func(cx *core.Scope, r core.ListRow) core.Node {
return core.Text{ContentFunc: func() string { return rowText(ids.Get()[r.Index()]) }, Style: core.Style{Height: core.Pt(40)}}
}}
})
a.ScrollTo("id:list", core.Point{Y: 1000})
a.Post(func() {
ids.Set(slices.Insert(slices.Clone(ids.Get()), 20, 1000))
ref.ScrollToIndexAt(20, 0, 0, animated)
})
a.Settle()
list := a.Find("id:list")
if got := onScreen(t, a, list, 1000); got != 0 {
t.Errorf("animated %v: the inserted row is %v from the viewport's start, want 0", animated, got)
}
if list.Offset.Y != 800 {
t.Errorf("animated %v: offset %v, want 800", animated, list.Offset.Y)
}
}
}

func makeIDs(n, from int) []int {
out := make([]int, n)
for i := range out {
Expand Down