Skip to content
Merged
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
2 changes: 1 addition & 1 deletion internal/ui/search_creators.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (s *Shell) viewSearchLead(c *ui.Context, keyword string, tab int) {
for i := range tabs {
tabs[i] = pud.Tab{Label: searchTabLabels[i], Count: s.searchTabCountText(i)}
}
pud.Tabs(c, "search:tabs", &s.search.tab, tabs)
pud.Tabs(c, "search:tabs:"+keyword, &s.search.tab, tabs)
})
s.viewSearchToolbar(c, tab)

Expand Down
9 changes: 7 additions & 2 deletions internal/ui/searchpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func (s *Shell) syncSearch(c *ui.Context) {
s.syncCreatorPreview(keyword)

cur := st.tab
if st.tabKeyword != keyword {
st.tab = searchTabSong
st.tabKeyword = keyword
cur = searchTabSong
}
// 🔴 换查询 → 重置到第 1 页(理由见 searchTab.current)。
//
// ⚠️ **判的是上一帧的那张 Tab**:这一层的副作用跑在画的前面,而 Tab 是
Expand Down Expand Up @@ -235,7 +240,7 @@ func (s *Shell) viewSearchResults(c *ui.Context, keyword string, winW float32) {
for i := range tabs {
tabs[i] = pud.Tab{Label: searchTabLabels[i], Count: s.searchTabCountText(i)}
}
pud.Tabs(c, "search:tabs", &st.tab, tabs)
pud.Tabs(c, "search:tabs:"+keyword, &st.tab, tabs)
})
s.viewSearchToolbar(c, cur)
}
Expand Down Expand Up @@ -361,7 +366,7 @@ func (s *Shell) viewSearchResultsBody(c *ui.Context, tab int, keyword string, le
t.list.Header(c, "search:header:"+strconv.Itoa(tab))
}
if tab == searchTabUser {
ui.Box(c).Height(space.Px8)
ui.Box(c).Height(space.Px16)
}
t.list.View(c)
}
Expand Down
23 changes: 21 additions & 2 deletions internal/ui/searchpage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,27 @@ func TestSearchUserCardsKeepClearanceBelowTheToolbar(t *testing.T) {
if !ok {
t.Fatal("找不到第一张 UP 主卡")
}
if gap := card.Y - (toolbar.Y + toolbar.H); gap < 8 {
t.Fatalf("排序控件和第一张 UP 主卡之间只有 %.1fpx,至少需要 8px", gap)
if gap := card.Y - (toolbar.Y + toolbar.H); gap < 16 {
t.Fatalf("排序控件和第一张 UP 主卡之间只有 %.1fpx,至少需要 16px", gap)
}
}

// TestChangingSearchKeywordReturnsToSongs locks the default result type for a new search.
func TestChangingSearchKeywordReturnsToSongs(t *testing.T) {
s, tt := newSearchPage(t, "周杰伦", newSearchStub(24, 24))
settleText(t, tt, "第 1 页 第 1 首")
if err := tt.Click("UP 主"); err != nil {
t.Fatal(err)
}
waitFrames(t, tt, "用户那一页进来", loadedTo(s, searchTabUser, 1))

s.navigate(searchPath + "?" + searchQuery + "=" + url.QueryEscape("林俊杰"))
waitFrames(t, tt, "新搜索结果出现", func() bool { return tt.HasText("第 1 页 第 1 首") })
if s.search.tab != searchTabSong {
t.Fatalf("新搜索默认 Tab = %d,want 歌曲(%d)", s.search.tab, searchTabSong)
}
if !tt.HasText("歌曲") {
t.Fatalf("新搜索没有回到歌曲 Tab,文字有 %q", tt.Texts())
}
}

Expand Down
3 changes: 3 additions & 0 deletions internal/ui/searchresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ type searchState struct {
creators creatorPreview
// tab 是当前选中的 Tab(`ui.Tabs` 直接写它)。
tab int
// tabKeyword 是当前 Tab 选择对应的搜索词。换词时默认回到歌曲结果,用户在
// 同一个词里手动切换到视频或 UP 主则保留当前 Tab。
tabKeyword string

// sortOpen 是排序下拉此刻是不是展开的(一次只会展开一个)。
sortOpen bool
Expand Down
Loading