@@ -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
518521func (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