File tree Expand file tree Collapse file tree 4 files changed +10
-10
lines changed
Expand file tree Collapse file tree 4 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -521,3 +521,10 @@ func (panel *FilePanel) RefreshData(displayDotFile bool) {
521521 }
522522 panel .LastTimeGetElement = time .Now ()
523523}
524+
525+ func (panel * FilePanel ) ResetIndexIfInvalid () {
526+ if panel .Cursor < 0 || panel .Cursor >= panel .ElementCount () {
527+ panel .Cursor = 0
528+ panel .RenderIndex = 0
529+ }
530+ }
Original file line number Diff line number Diff line change @@ -436,9 +436,7 @@ func (m *model) updateFilePanelsState(msg tea.Msg) tea.Cmd {
436436
437437 // TODO : This is like duct taping a bigger problem
438438 // The code should never reach this state.
439- if focusPanel .Cursor < 0 {
440- focusPanel .Cursor = 0
441- }
439+ focusPanel .ResetIndexIfInvalid ()
442440
443441 return cmd
444442}
Original file line number Diff line number Diff line change @@ -124,7 +124,6 @@ func TestFilePanelNavigation(t *testing.T) {
124124 m := defaultTestModel (tt .startDir )
125125 m .getFocusedFilePanel ().Cursor = tt .startCursor
126126 m .getFocusedFilePanel ().RenderIndex = tt .startRender
127- m .getFocusedFilePanel ().SearchBar .SetValue ("asdf" )
128127 for _ , s := range tt .keyInput {
129128 TeaUpdateWithErrCheck (m , utils .TeaRuneKeyMsg (s ))
130129 }
@@ -141,7 +140,7 @@ func TestFilePanelNavigation(t *testing.T) {
141140 TeaUpdateWithErrCheck (m , utils .TeaRuneKeyMsg ("cd " + tt .startDir ))
142141 TeaUpdateWithErrCheck (m , tea.KeyMsg {Type : tea .KeyEnter })
143142
144- // Make sure we have original curson and render
143+ // Make sure we have original cursor and render
145144 assert .Equal (t , tt .startCursor , m .getFocusedFilePanel ().Cursor )
146145 assert .Equal (t , tt .startRender , m .getFocusedFilePanel ().RenderIndex )
147146 })
Original file line number Diff line number Diff line change @@ -32,11 +32,7 @@ func (m *model) filePanelRender() string {
3232 // check if cursor or render out of range
3333 // TODO - instead of this, have a filepanel.validateAndFix(), and log Error
3434 // This should not ever happen
35- if filePanel .Cursor > filePanel .ElementCount ()- 1 {
36- filePanel .Cursor = 0
37- filePanel .RenderIndex = 0
38- }
39- m .fileModel .filePanels [i ] = filePanel
35+ m .fileModel .filePanels [i ].ResetIndexIfInvalid ()
4036
4137 // TODO : Move this to a utility function and clarify the calculation via comments
4238 // Maybe even write unit tests
You can’t perform that action at this time.
0 commit comments