feat: add ctrl+b to toggle file tree

This commit is contained in:
2026-01-27 03:48:07 +00:00
parent e555d74b51
commit d962b7a7ad
+23 -7
View File
@@ -32,6 +32,7 @@ type model struct {
isHoveringDivider bool isHoveringDivider bool
contentHeight int contentHeight int
showStatusBar bool showStatusBar bool
showSidebar bool
// input handling // input handling
textInput textinput.Model textInput textinput.Model
inputMode bool inputMode bool
@@ -48,6 +49,7 @@ func NewModel(rootPath string) *model {
loading: true, loading: true,
noteView: note.NewNoteView(), noteView: note.NewNoteView(),
showStatusBar: false, showStatusBar: false,
showSidebar: true,
textInput: ti, textInput: ti,
} }
} }
@@ -83,7 +85,12 @@ func (m *model) layout(width, height int) {
if m.tree != nil { if m.tree != nil {
minW = m.tree.ContentWidth() minW = m.tree.ContentWidth()
} }
m.fsTreeWidth, m.noteViewWidth = getUpdatedWindowSizes(width, m.fsTreeWidth, minW) if !m.showSidebar {
m.fsTreeWidth = 0
m.noteViewWidth = width
} else {
m.fsTreeWidth, m.noteViewWidth = getUpdatedWindowSizes(width, m.fsTreeWidth, minW)
}
h := height h := height
if m.showStatusBar || m.inputMode { if m.showStatusBar || m.inputMode {
@@ -216,6 +223,10 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg.String() { switch msg.String() {
case "q", "ctrl+c": case "q", "ctrl+c":
return m, tea.Quit return m, tea.Quit
case "ctrl+b":
m.showSidebar = !m.showSidebar
m.layout(m.terminalWidth, m.terminalHeight)
return m, m.resizeChildren()
case "i": case "i":
m.showStatusBar = !m.showStatusBar m.showStatusBar = !m.showStatusBar
m.layout(m.terminalWidth, m.terminalHeight) m.layout(m.terminalWidth, m.terminalHeight)
@@ -329,12 +340,17 @@ func (m model) View() string {
notes := m.noteView.View() notes := m.noteView.View()
full := lipgloss.JoinHorizontal( var full string
lipgloss.Top, if m.showSidebar {
tree, full = lipgloss.JoinHorizontal(
divider, lipgloss.Top,
notes, tree,
) divider,
notes,
)
} else {
full = notes
}
if !m.showStatusBar && !m.inputMode { if !m.showStatusBar && !m.inputMode {
return full return full