From e75b3eb4182866b350aa4b1b12eb8feef9ad22e5 Mon Sep 17 00:00:00 2001 From: Joe Julian Date: Fri, 3 Apr 2026 10:38:14 -0700 Subject: [PATCH] Harden phone entry click state --- main.go | 12 ++++++++++-- main_test.go | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index e3aaf67..d27620c 100644 --- a/main.go +++ b/main.go @@ -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] diff --git a/main_test.go b/main_test.go index fa920d1..a8d6f56 100644 --- a/main_test.go +++ b/main_test.go @@ -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()