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 viewStart int
viewEnd int viewEnd int
oldSelected *FsNode oldSelected *FsNode
startOffset int
} }
// ==================== Bubble Tea Interface Implementation ==================== // ==================== Bubble Tea Interface Implementation ====================
@@ -106,7 +107,7 @@ func (t *FsTree) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
case tea.MouseMsg: case tea.MouseMsg:
m.Y += t.viewStart // adjust for viewport m.Y += t.viewStart - t.startOffset // adjust for viewport
if m.X >= t.width { if m.X >= t.width {
break break
} }
@@ -184,7 +185,7 @@ func (t *FsTree) View() string {
// ==================== FsTree helper methods ==================== // ==================== FsTree helper methods ====================
func NewFsTree(rootPath string) *FsTree { func NewFsTree(rootPath string, startOffset int) *FsTree {
root := &FsNode{ root := &FsNode{
nodeType: FolderNode, nodeType: FolderNode,
path: rootPath, path: rootPath,
@@ -194,7 +195,8 @@ func NewFsTree(rootPath string) *FsTree {
walkFileSystemAndBuildTree(rootPath, root) walkFileSystemAndBuildTree(rootPath, root)
tree := &FsTree{ tree := &FsTree{
root: root, root: root,
startOffset: startOffset,
} }
if len(root.children) > 0 { if len(root.children) > 0 {
tree.selectedNode = root.children[0] tree.selectedNode = root.children[0]
+5 -4
View File
@@ -2,10 +2,11 @@ package main
// layout constants // layout constants
const ( const (
minFsTreeWidth = 5 minFsTreeWidth = 5
minNoteViewWidth = 10 minNoteViewWidth = 10
dividerWidth = 1 dividerWidth = 1
dragHitArea = 2 // +/- chars around divider dragHitArea = 2 // +/- chars around divider
fsTreeStartOffset = 1
) )
// calculateLayout computes the widths for the file tree and note view // 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 { } else {
targetPath = path targetPath = path
} }
return treeLoadedMsg{tree: NewFsTree(targetPath)} return treeLoadedMsg{tree: NewFsTree(targetPath, fsTreeStartOffset)}
} }
} }
func (m *model) layout(width, height int) { func (m *model) layout(width, height int) {
m.terminalWidth = width m.terminalWidth = width
m.terminalHeight = height m.terminalHeight = height
m.fsTreeWidth, m.noteViewWidth = calculateLayout(width, m.fsTreeWidth) 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": case "q", "ctrl+c":
return m, tea.Quit return m, tea.Quit
} }
var cmds []tea.Cmd var cmds []tea.Cmd
// Forward keyboard input to tree // Forward keyboard input to tree
@@ -206,6 +206,7 @@ func (m model) View() string {
Height(m.terminalHeight). Height(m.terminalHeight).
Width(m.fsTreeWidth). Width(m.fsTreeWidth).
Align(lipgloss.Left). Align(lipgloss.Left).
PaddingTop(fsTreeStartOffset).
PaddingRight(1). PaddingRight(1).
Render(tree) Render(tree)