Skip to content

Commit 89e9a93

Browse files
committed
fix(viewport): Reset cursor position when changing file list
Adds explicit cursor and viewport reset logic when the file list changes due to searching, filtering, or refreshing. This ensures the cursor is always at a valid position and the viewport shows from the top of the list when: - Exiting search mode - Refreshing the file list - Toggling gitignore filters - Toggling hidden file display - Starting a new search
1 parent f740e85 commit 89e9a93

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

internal/model/init_update.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
141141
m.searchInput.Blur()
142142
m.searchInput.SetValue("")
143143
m.searchResults = nil
144+
m.cursor = 0
145+
m.viewport.GotoTop()
144146
m.collapseAllDirectories()
145147
m.refreshViewportContent()
146148
return m, nil
@@ -200,6 +202,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
200202
m.deselected = make(map[string]bool)
201203
m.isDependency = make(map[string]bool)
202204
m.cursor = 0
205+
m.viewport.GotoTop()
203206
return m, tea.Sequence(
204207
m.reloadFiles(),
205208
func() tea.Msg { return refreshMsg{} },
@@ -257,6 +260,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
257260
m.searchInput.Focus()
258261
m.searchInput.SetValue("")
259262
m.searchResults = nil
263+
m.cursor = 0
264+
m.viewport.GotoTop()
260265
m.expandAllDirectories()
261266
m.refreshViewportContent()
262267
return m, nil
@@ -278,11 +283,15 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
278283
m.useGitIgnore = !m.useGitIgnore
279284
m.generator.UseGitIgnore = m.useGitIgnore
280285
m.filterSelections()
286+
m.cursor = 0
287+
m.viewport.GotoTop()
281288
return m, m.reloadFiles()
282289
case ".":
283290
m.showHidden = !m.showHidden
284291
m.generator.ShowHidden = m.showHidden
285292
m.filterSelections()
293+
m.cursor = 0
294+
m.viewport.GotoTop()
286295
return m, m.reloadFiles()
287296
case "D":
288297
m.resolveDeps = !m.resolveDeps

0 commit comments

Comments
 (0)