@@ -17,6 +17,7 @@ type CollectionsView struct {
1717 width int
1818 height int
1919 initialized bool
20+ selectedIndex int
2021
2122 // Backend pagination state
2223 currentPage int
@@ -36,7 +37,22 @@ func (v CollectionsView) Init() tea.Cmd {
3637}
3738
3839func (v * CollectionsView ) loadCollections () tea.Msg {
39- return v .loadCollectionsPage (1 , 20 ) // Load first page with 20 items
40+ pageToLoad := v .currentPage
41+ if pageToLoad == 0 {
42+ pageToLoad = 1
43+ }
44+ pageSizeToLoad := v .pageSize
45+ if pageSizeToLoad == 0 {
46+ pageSizeToLoad = 20
47+ }
48+
49+ if v .initialized {
50+ v .selectedIndex = v .list .SelectedIndex ()
51+ } else {
52+ v .selectedIndex = 0
53+ }
54+
55+ return v .loadCollectionsPage (pageToLoad , pageSizeToLoad )
4056}
4157
4258func (v * CollectionsView ) loadCollectionsPage (page , pageSize int ) tea.Msg {
@@ -93,6 +109,7 @@ func (v CollectionsView) Update(msg tea.Msg) (CollectionsView, tea.Cmd) {
93109 // Create list with pagination info in title
94110 title := fmt .Sprintf ("Collections (Page %d/%d)" , v .currentPage , v .pagination .TotalPages )
95111 v .list = components .NewPaginatedList (items , title )
112+ v .list .SetIndex (v .selectedIndex )
96113
97114 if v .width > 0 && v .height > 0 {
98115 contentHeight := v .height - 4
@@ -115,6 +132,7 @@ func (v CollectionsView) Update(msg tea.Msg) (CollectionsView, tea.Cmd) {
115132 case "n" , "right" :
116133 // Next page
117134 if v .currentPage < v .pagination .TotalPages {
135+ v .selectedIndex = 0 // Reset selection on page change
118136 return v , func () tea.Msg {
119137 return v .loadCollectionsPage (v .currentPage + 1 , v .pageSize )
120138 }
@@ -123,6 +141,7 @@ func (v CollectionsView) Update(msg tea.Msg) (CollectionsView, tea.Cmd) {
123141 case "p" , "left" :
124142 // Previous page
125143 if v .currentPage > 1 {
144+ v .selectedIndex = 0 // Reset selection on page change
126145 return v , func () tea.Msg {
127146 return v .loadCollectionsPage (v .currentPage - 1 , v .pageSize )
128147 }
@@ -147,6 +166,13 @@ func (v CollectionsView) IsFiltering() bool {
147166 return v .initialized && v .list .IsFiltering ()
148167}
149168
169+ func (v * CollectionsView ) SetSelectedIndex (index int ) {
170+ v .selectedIndex = index
171+ if v .initialized {
172+ v .list .SetIndex (index )
173+ }
174+ }
175+
150176func (v CollectionsView ) GetSelectedItem () * collections.CollectionEntity {
151177 if ! v .initialized {
152178 return nil
@@ -160,6 +186,10 @@ func (v CollectionsView) GetSelectedItem() *collections.CollectionEntity {
160186 return nil
161187}
162188
189+ func (v CollectionsView ) GetSelectedIndex () int {
190+ return v .list .SelectedIndex ()
191+ }
192+
163193func (v CollectionsView ) View () string {
164194 if ! v .initialized {
165195 return v .layout .FullView (
0 commit comments