Harden phone entry click state

This commit is contained in:
Joe Julian
2026-04-03 10:38:14 -07:00
parent ae7483e929
commit e75b3eb418
2 changed files with 32 additions and 2 deletions
+10 -2
View File
@@ -645,13 +645,21 @@ func (u *ui) filter() {
return
}
u.visible = visible
if len(u.entryClicks) < len(u.visible) {
u.entryClicks = make([]widget.Clickable, len(u.visible))
u.ensureEntryClicks()
}
func (u *ui) ensureEntryClicks() {
if len(u.entryClicks) >= len(u.visible) {
return
}
next := make([]widget.Clickable, len(u.visible))
copy(next, u.entryClicks)
u.entryClicks = next
}
func (u *ui) visibleEntrySnapshot() ([]entry, []*widget.Clickable) {
visible := append([]entry(nil), u.visible...)
u.ensureEntryClicks()
clicks := make([]*widget.Clickable, len(visible))
for i := range visible {
clicks[i] = &u.entryClicks[i]
+22
View File
@@ -849,6 +849,28 @@ func TestUIVisibleEntrySnapshotIsStableAfterVisibleMutation(t *testing.T) {
}
}
func TestUIVisibleEntrySnapshotRegrowsClickableState(t *testing.T) {
t.Parallel()
u := newUIWithModel("phone", vault.Model{
Entries: []vault.Entry{
{ID: "1", Title: "Alpha", Path: []string{"Crew", "Internet"}},
{ID: "2", Title: "Beta", Path: []string{"Crew", "Internet"}},
},
})
u.state.NavigateToPath([]string{"Crew", "Internet"})
u.filter()
u.entryClicks = u.entryClicks[:1]
visible, clicks := u.visibleEntrySnapshot()
if len(visible) != 2 || len(clicks) != 2 {
t.Fatalf("snapshot lengths = (%d, %d), want (2, 2)", len(visible), len(clicks))
}
if clicks[1] == nil {
t.Fatal("regrown click pointer = nil, want usable clickable state")
}
}
func TestUIPhoneBackReturnsFromSubscreenToEntries(t *testing.T) {
t.Parallel()