@@ -107,14 +107,12 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
107107 cmds = append (cmds , dfCmd )
108108 case "up" , "k" , "ctrl+p" :
109109 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 )
112111 cmds = append (cmds , cmd )
113112 }
114113 case "down" , "j" , "ctrl+n" :
115114 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 )
118116 cmds = append (cmds , cmd )
119117 }
120118 }
@@ -134,7 +132,7 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
134132 return m , tea .Quit
135133 }
136134 m .fileTree = m .fileTree .SetFiles (m .files )
137- m . diffViewer , cmd = m .diffViewer . SetFilePatch ( m . files [ 0 ] )
135+ cmd = m .setCursor ( 0 )
138136 cmds = append (cmds , cmd )
139137
140138 case common.ErrMsg :
@@ -147,8 +145,6 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
147145 cmds = append (cmds , sCmds ... )
148146 }
149147
150- m .fileTree = m .fileTree .SetCursor (m .cursor )
151-
152148 m .diffViewer , cmd = m .diffViewer .Update (msg )
153149 cmds = append (cmds , cmd )
154150
@@ -309,3 +305,11 @@ func (m *mainModel) stopSearch() {
309305 m .search .Blur ()
310306 m .search .Width = m .sidebarWidth () - 5
311307}
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