Skip to content

Commit e12383c

Browse files
committed
fix: filetree viewport double offset
1 parent 4bfc333 commit e12383c

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pkg/ui/mainModel.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

pkg/ui/panes/filetree/filetree.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const contextLines = 15
4848

4949
func (m *Model) scrollSelectedFileIntoView(t *tree.Tree) {
5050
children := t.Children()
51+
found := false
5152
for i := 0; i < children.Length(); i++ {
5253
child := children.At(i)
5354
switch child := child.(type) {
@@ -62,8 +63,13 @@ func (m *Model) scrollSelectedFileIntoView(t *tree.Tree) {
6263
offset = offset - 1
6364
}
6465
m.vp.SetYOffset(offset)
66+
found = true
67+
break
6568
}
6669
}
70+
if found {
71+
break
72+
}
6773
}
6874
}
6975

0 commit comments

Comments
 (0)