fix incorrect line count in fstree
This commit is contained in:
@@ -78,6 +78,7 @@ type FsTree struct {
|
|||||||
width int
|
width int
|
||||||
viewStart int
|
viewStart int
|
||||||
viewEnd int
|
viewEnd int
|
||||||
|
totalLines int
|
||||||
oldSelected *FsNode
|
oldSelected *FsNode
|
||||||
startOffset int
|
startOffset int
|
||||||
}
|
}
|
||||||
@@ -120,6 +121,15 @@ func (t *FsTree) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case tea.MouseMsg:
|
case tea.MouseMsg:
|
||||||
|
if m.Action == tea.MouseActionPress {
|
||||||
|
switch m.Button {
|
||||||
|
case tea.MouseButtonWheelUp:
|
||||||
|
_ = t.MoveUp()
|
||||||
|
case tea.MouseButtonWheelDown:
|
||||||
|
_ = t.MoveDown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m.Y += t.viewStart - t.startOffset // adjust for viewport
|
m.Y += t.viewStart - t.startOffset // adjust for viewport
|
||||||
if m.X >= t.width {
|
if m.X >= t.width {
|
||||||
break
|
break
|
||||||
@@ -139,7 +149,7 @@ func (t *FsTree) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.viewStart, t.viewEnd = t.getViewportBounds(len(t.lines))
|
t.viewStart, t.viewEnd = t.getViewportBounds()
|
||||||
|
|
||||||
if t.oldSelected != t.selectedNode {
|
if t.oldSelected != t.selectedNode {
|
||||||
t.oldSelected = t.selectedNode
|
t.oldSelected = t.selectedNode
|
||||||
@@ -162,18 +172,15 @@ func (t *FsTree) PerformAction(action FsActionType, name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *FsTree) getViewportBounds(totalLines int) (startLine, endLine int) {
|
func (t *FsTree) getViewportBounds() (startLine, endLine int) {
|
||||||
selectedLine := t.selectedNode.line
|
selectedLine := t.selectedNode.line
|
||||||
halfHeight := t.height / 2
|
halfHeight := t.height / 2
|
||||||
|
|
||||||
startLine = selectedLine - halfHeight
|
startLine = max(0, selectedLine-halfHeight)
|
||||||
if startLine < 0 {
|
|
||||||
startLine = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
endLine = startLine + t.height
|
endLine = startLine + t.height
|
||||||
if endLine > totalLines {
|
if endLine > t.totalLines {
|
||||||
endLine = totalLines
|
endLine = t.totalLines
|
||||||
startLine = endLine - t.height
|
startLine = endLine - t.height
|
||||||
if startLine < 0 {
|
if startLine < 0 {
|
||||||
startLine = 0
|
startLine = 0
|
||||||
@@ -370,6 +377,7 @@ func (t *FsTree) buildLines() {
|
|||||||
// everything is a child of root
|
// everything is a child of root
|
||||||
flatTree[0] = nil // basically a merge of skip root and padding ends with nil
|
flatTree[0] = nil // basically a merge of skip root and padding ends with nil
|
||||||
flatTree = append(flatTree, nil)
|
flatTree = append(flatTree, nil)
|
||||||
|
t.totalLines = line
|
||||||
|
|
||||||
for i := 1; i < len(flatTree)-1; i++ {
|
for i := 1; i < len(flatTree)-1; i++ {
|
||||||
flatTree[i].prev = flatTree[i-1]
|
flatTree[i].prev = flatTree[i-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user