adjustStoriesScroll ensures the selected index is visible in the scroll window.
()
| 2139 | |
| 2140 | // adjustStoriesScroll ensures the selected index is visible in the scroll window. |
| 2141 | func (a *App) adjustStoriesScroll() { |
| 2142 | listHeight := a.storiesListHeight() |
| 2143 | if listHeight <= 0 { |
| 2144 | return |
| 2145 | } |
| 2146 | if a.selectedIndex < a.storiesScrollOffset { |
| 2147 | a.storiesScrollOffset = a.selectedIndex |
| 2148 | } |
| 2149 | if a.selectedIndex >= a.storiesScrollOffset+listHeight { |
| 2150 | a.storiesScrollOffset = a.selectedIndex - listHeight + 1 |
| 2151 | } |
| 2152 | // Clamp |
| 2153 | maxOffset := len(a.prd.UserStories) - listHeight |
| 2154 | if maxOffset < 0 { |
| 2155 | maxOffset = 0 |
| 2156 | } |
| 2157 | if a.storiesScrollOffset > maxOffset { |
| 2158 | a.storiesScrollOffset = maxOffset |
| 2159 | } |
| 2160 | if a.storiesScrollOffset < 0 { |
| 2161 | a.storiesScrollOffset = 0 |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | // markStoryInProgress clears any existing in-progress flags and marks the |
| 2166 | // given story as in-progress, then reloads the PRD from disk. |