@@ -107,14 +107,12 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
107
107
cmds = append (cmds , dfCmd )
108
108
case "up" , "k" , "ctrl+p" :
109
109
if m .cursor > 0 {
110
- m .cursor --
111
- m .diffViewer , cmd = m .diffViewer .SetFilePatch (m .files [m .cursor ])
110
+ cmd = m .setCursor (m .cursor - 1 )
112
111
cmds = append (cmds , cmd )
113
112
}
114
113
case "down" , "j" , "ctrl+n" :
115
114
if m .cursor < len (m .files )- 1 {
116
- m .cursor ++
117
- m .diffViewer , cmd = m .diffViewer .SetFilePatch (m .files [m .cursor ])
115
+ cmd = m .setCursor (m .cursor + 1 )
118
116
cmds = append (cmds , cmd )
119
117
}
120
118
}
@@ -134,7 +132,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
134
132
return m , tea .Quit
135
133
}
136
134
m .fileTree = m .fileTree .SetFiles (m .files )
137
- m . diffViewer , cmd = m .diffViewer . SetFilePatch ( m . files [ 0 ] )
135
+ cmd = m .setCursor ( 0 )
138
136
cmds = append (cmds , cmd )
139
137
140
138
case common.ErrMsg :
@@ -147,8 +145,6 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
147
145
cmds = append (cmds , sCmds ... )
148
146
}
149
147
150
- m .fileTree = m .fileTree .SetCursor (m .cursor )
151
-
152
148
m .diffViewer , cmd = m .diffViewer .Update (msg )
153
149
cmds = append (cmds , cmd )
154
150
@@ -309,3 +305,11 @@ func (m *mainModel) stopSearch() {
309
305
m .search .Blur ()
310
306
m .search .Width = m .sidebarWidth () - 5
311
307
}
308
+
309
+ func (m * mainModel ) setCursor (cursor int ) tea.Cmd {
310
+ var cmd tea.Cmd
311
+ m .cursor = cursor
312
+ m .diffViewer , cmd = m .diffViewer .SetFilePatch (m .files [m .cursor ])
313
+ m .fileTree = m .fileTree .SetCursor (m .cursor )
314
+ return cmd
315
+ }
0 commit comments