feat(ui): use t to toggle tree on/off
This commit is contained in:
parent
a8303b51fa
commit
dd4544b2d0
|
|
@ -56,9 +56,10 @@ type Model struct {
|
|||
inputBuffer string
|
||||
pendingZ bool
|
||||
|
||||
focus Focus
|
||||
showHelp bool
|
||||
flatMode bool
|
||||
focus Focus
|
||||
showHelp bool
|
||||
flatMode bool
|
||||
treeHidden bool
|
||||
|
||||
width, height int
|
||||
}
|
||||
|
|
@ -202,6 +203,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
|
||||
switch msg.String() {
|
||||
case "tab":
|
||||
if m.treeHidden {
|
||||
return m, nil
|
||||
}
|
||||
if m.focus == FocusTree {
|
||||
if item, ok := m.fileList.SelectedItem().(tree.TreeItem); ok && item.IsDir {
|
||||
return m, nil
|
||||
|
|
@ -224,8 +228,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
m.inputBuffer = ""
|
||||
|
||||
case "h", "[", "ctrl+h", "left":
|
||||
m.focus = FocusTree
|
||||
m.updateTreeFocus()
|
||||
if !m.treeHidden {
|
||||
m.focus = FocusTree
|
||||
m.updateTreeFocus()
|
||||
}
|
||||
m.inputBuffer = ""
|
||||
|
||||
case "enter":
|
||||
|
|
@ -293,6 +299,18 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
m.inputBuffer = ""
|
||||
return m, nil
|
||||
|
||||
case "t":
|
||||
m.treeHidden = !m.treeHidden
|
||||
if m.treeHidden {
|
||||
m.focus = FocusDiff
|
||||
} else {
|
||||
m.focus = FocusTree
|
||||
}
|
||||
m.updateTreeFocus()
|
||||
m.updateSizes()
|
||||
m.inputBuffer = ""
|
||||
return m, nil
|
||||
|
||||
case "z":
|
||||
if m.focus == FocusDiff {
|
||||
m.pendingZ = true
|
||||
|
|
@ -478,20 +496,25 @@ func (m *Model) updateSizes() {
|
|||
contentHeight = 1
|
||||
}
|
||||
|
||||
treeWidth := int(float64(m.width) * 0.20)
|
||||
if treeWidth < 20 {
|
||||
treeWidth = 20
|
||||
}
|
||||
|
||||
// Subtract border height (2) from contentHeight
|
||||
listHeight := contentHeight - 2
|
||||
if listHeight < 1 {
|
||||
listHeight = 1
|
||||
}
|
||||
m.fileList.SetSize(treeWidth, listHeight)
|
||||
|
||||
m.diffViewport.Width = m.width - treeWidth - 4 // border (2) + padding (2) from tree pane
|
||||
m.diffViewport.Height = listHeight
|
||||
if m.treeHidden {
|
||||
m.fileList.SetSize(0, listHeight)
|
||||
m.diffViewport.Width = m.width - 2 // border (2)
|
||||
m.diffViewport.Height = listHeight
|
||||
} else {
|
||||
treeWidth := int(float64(m.width) * 0.20)
|
||||
if treeWidth < 20 {
|
||||
treeWidth = 20
|
||||
}
|
||||
m.fileList.SetSize(treeWidth, listHeight)
|
||||
m.diffViewport.Width = m.width - treeWidth - 4 // border (2) + padding (2) from tree pane
|
||||
m.diffViewport.Height = listHeight
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) updateTreeFocus() {
|
||||
|
|
@ -645,7 +668,11 @@ func (m Model) View() string {
|
|||
rightPaneView = lipgloss.JoinVertical(lipgloss.Top, header, diffView)
|
||||
}
|
||||
|
||||
mainContent = lipgloss.JoinHorizontal(lipgloss.Top, treeView, rightPaneView)
|
||||
if m.treeHidden {
|
||||
mainContent = rightPaneView
|
||||
} else {
|
||||
mainContent = lipgloss.JoinHorizontal(lipgloss.Top, treeView, rightPaneView)
|
||||
}
|
||||
}
|
||||
|
||||
var bottomBar string
|
||||
|
|
@ -696,7 +723,7 @@ func (m Model) renderTopBar() string {
|
|||
}
|
||||
|
||||
func (m Model) viewStatusBar() string {
|
||||
shortcuts := StatusKeyStyle.Render("? Help q Quit Tab Switch f Flat")
|
||||
shortcuts := StatusKeyStyle.Render("? Help q Quit Tab Switch f Flat t Tree")
|
||||
return StatusBarStyle.Width(m.width).Render(shortcuts)
|
||||
}
|
||||
|
||||
|
|
@ -717,6 +744,7 @@ func (m Model) renderHelpDrawer() string {
|
|||
HelpTextStyle.Render("H/M/L Move Cursor"),
|
||||
HelpTextStyle.Render("e Edit File"),
|
||||
HelpTextStyle.Render("f Flat Tree"),
|
||||
HelpTextStyle.Render("t Toggle Tree"),
|
||||
)
|
||||
|
||||
return HelpDrawerStyle.Copy().
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user