Skip to content

Commit ad8e7ae

Browse files
committed
fix: go to top of diff when switching files
1 parent 62eefe8 commit ad8e7ae

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

pkg/ui/mainModel.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ 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.diffViewer.GoToTop()
110111
cmd = m.setCursor(m.cursor - 1)
111112
cmds = append(cmds, cmd)
112113
}
113114
case "down", "j", "ctrl+n":
114115
if m.cursor < len(m.files)-1 {
116+
m.diffViewer.GoToTop()
115117
cmd = m.setCursor(m.cursor + 1)
116118
cmds = append(cmds, cmd)
117119
}

pkg/ui/panes/diffviewer/diffviewer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (m Model) SetFilePatch(file *gitdiff.File) (Model, tea.Cmd) {
112112
return m, diff(m.file, m.Width)
113113
}
114114

115+
func (m *Model) GoToTop() {
116+
m.vp.GotoTop()
117+
}
118+
115119
func diff(file *gitdiff.File, width int) tea.Cmd {
116120
if width == 0 || file == nil {
117121
return nil

0 commit comments

Comments
 (0)