add handling for offseting fsTree start
This commit is contained in:
@@ -62,6 +62,7 @@ type FsTree struct {
|
||||
viewStart int
|
||||
viewEnd int
|
||||
oldSelected *FsNode
|
||||
startOffset int
|
||||
}
|
||||
|
||||
// ==================== Bubble Tea Interface Implementation ====================
|
||||
@@ -106,7 +107,7 @@ func (t *FsTree) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
case tea.MouseMsg:
|
||||
m.Y += t.viewStart // adjust for viewport
|
||||
m.Y += t.viewStart - t.startOffset // adjust for viewport
|
||||
if m.X >= t.width {
|
||||
break
|
||||
}
|
||||
@@ -184,7 +185,7 @@ func (t *FsTree) View() string {
|
||||
|
||||
// ==================== FsTree helper methods ====================
|
||||
|
||||
func NewFsTree(rootPath string) *FsTree {
|
||||
func NewFsTree(rootPath string, startOffset int) *FsTree {
|
||||
root := &FsNode{
|
||||
nodeType: FolderNode,
|
||||
path: rootPath,
|
||||
@@ -195,6 +196,7 @@ func NewFsTree(rootPath string) *FsTree {
|
||||
|
||||
tree := &FsTree{
|
||||
root: root,
|
||||
startOffset: startOffset,
|
||||
}
|
||||
if len(root.children) > 0 {
|
||||
tree.selectedNode = root.children[0]
|
||||
|
||||
@@ -6,6 +6,7 @@ const (
|
||||
minNoteViewWidth = 10
|
||||
dividerWidth = 1
|
||||
dragHitArea = 2 // +/- chars around divider
|
||||
fsTreeStartOffset = 1
|
||||
)
|
||||
|
||||
// calculateLayout computes the widths for the file tree and note view
|
||||
|
||||
@@ -73,7 +73,7 @@ func (m *model) loadTreeCmd(path string) tea.Cmd {
|
||||
} else {
|
||||
targetPath = path
|
||||
}
|
||||
return treeLoadedMsg{tree: NewFsTree(targetPath)}
|
||||
return treeLoadedMsg{tree: NewFsTree(targetPath, fsTreeStartOffset)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ func (m model) View() string {
|
||||
Height(m.terminalHeight).
|
||||
Width(m.fsTreeWidth).
|
||||
Align(lipgloss.Left).
|
||||
PaddingTop(fsTreeStartOffset).
|
||||
PaddingRight(1).
|
||||
Render(tree)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user