add handling for offseting fsTree start

This commit is contained in:
2026-01-04 02:54:34 +00:00
parent 92efbf61aa
commit 3ecc365a9b
3 changed files with 14 additions and 10 deletions
+5 -3
View File
@@ -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,
@@ -194,7 +195,8 @@ func NewFsTree(rootPath string) *FsTree {
walkFileSystemAndBuildTree(rootPath, root)
tree := &FsTree{
root: root,
root: root,
startOffset: startOffset,
}
if len(root.children) > 0 {
tree.selectedNode = root.children[0]
+5 -4
View File
@@ -2,10 +2,11 @@ package main
// layout constants
const (
minFsTreeWidth = 5
minNoteViewWidth = 10
dividerWidth = 1
dragHitArea = 2 // +/- chars around divider
minFsTreeWidth = 5
minNoteViewWidth = 10
dividerWidth = 1
dragHitArea = 2 // +/- chars around divider
fsTreeStartOffset = 1
)
// calculateLayout computes the widths for the file tree and note view
+4 -3
View File
@@ -73,14 +73,14 @@ func (m *model) loadTreeCmd(path string) tea.Cmd {
} else {
targetPath = path
}
return treeLoadedMsg{tree: NewFsTree(targetPath)}
return treeLoadedMsg{tree: NewFsTree(targetPath, fsTreeStartOffset)}
}
}
func (m *model) layout(width, height int) {
m.terminalWidth = width
m.terminalHeight = height
m.fsTreeWidth, m.noteViewWidth = calculateLayout(width, m.fsTreeWidth)
}
@@ -134,7 +134,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "q", "ctrl+c":
return m, tea.Quit
}
var cmds []tea.Cmd
// Forward keyboard input to tree
@@ -206,6 +206,7 @@ func (m model) View() string {
Height(m.terminalHeight).
Width(m.fsTreeWidth).
Align(lipgloss.Left).
PaddingTop(fsTreeStartOffset).
PaddingRight(1).
Render(tree)