Skip to content

Commit 2cba54b

Browse files
committed
feat: auto-hide sidebar when dragged below threshold
When user drags sidebar width below 10px, automatically hide it. Pressing 'e' to show the tree again resets to default width (26).
1 parent 4ddbe99 commit 2cba54b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pkg/ui/mainModel.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
118118
cmds = append(cmds, dfCmd, m.search.Focus())
119119
case "e":
120120
m.isShowingFileTree = !m.isShowingFileTree
121+
if m.isShowingFileTree {
122+
m.customSidebarWidth = 0 // Reset to default width.
123+
}
121124
dfCmd := m.diffViewer.SetSize(m.width-m.sidebarWidth(), m.height-m.footerHeight()-m.headerHeight())
122125
cmds = append(cmds, dfCmd)
123126
case "up", "k", "ctrl+p":
@@ -516,14 +519,22 @@ func (m mainModel) handleScroll(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
516519
}
517520

518521
func (m mainModel) handleSidebarDrag(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
519-
// Clamp to reasonable bounds
522+
// Hide sidebar if dragged below threshold.
523+
if msg.X < 10 {
524+
m.isShowingFileTree = false
525+
m.draggingSidebar = false
526+
cmd := m.diffViewer.SetSize(m.width, m.height-footerHeight-headerHeight)
527+
return m, cmd
528+
}
529+
530+
// Clamp to reasonable bounds.
520531
minWidth := 20
521532
maxWidth := m.width / 2
522533
newWidth := max(minWidth, min(maxWidth, msg.X))
523534

524535
m.customSidebarWidth = newWidth
525536

526-
// Resize components
537+
// Resize components.
527538
cmds := []tea.Cmd{}
528539
cmds = append(cmds, m.diffViewer.SetSize(m.width-m.sidebarWidth(), m.height-footerHeight-headerHeight))
529540
cmds = append(cmds, m.fileTree.SetSize(m.sidebarWidth(), m.height-footerHeight-headerHeight-searchHeight))

0 commit comments

Comments
 (0)