From 3ecc365a9b79ffbf9f98ad1131d52cde9146ee6c Mon Sep 17 00:00:00 2001 From: ruinivist Date: Sun, 4 Jan 2026 02:54:34 +0000 Subject: [PATCH] add handling for offseting fsTree start --- fstree.go | 8 +++++--- layout.go | 9 +++++---- main.go | 7 ++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/fstree.go b/fstree.go index 8eb209c..5bfaf1e 100644 --- a/fstree.go +++ b/fstree.go @@ -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] diff --git a/layout.go b/layout.go index 4b6bb18..dff7d34 100644 --- a/layout.go +++ b/layout.go @@ -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 diff --git a/main.go b/main.go index a2593c4..b7bc465 100644 --- a/main.go +++ b/main.go @@ -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)