Skip to content

Commit bf5dd1b

Browse files
committed
refactor: extract magic numbers to constants
Add constants for sidebar constraints and scroll speed: - sidebarMinWidth (20) - sidebarHideWidth (10) - scrollLines (3) Also add comment explaining Width(0) for grab line.
1 parent 1c9fcae commit bf5dd1b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/ui/mainModel.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ const (
3535

3636
// Sidebar resize detection threshold in pixels.
3737
sidebarGrabThreshold = 2
38+
39+
// Sidebar width constraints.
40+
sidebarMinWidth = 20
41+
sidebarHideWidth = 10
42+
43+
// Scroll speed in lines per wheel tick.
44+
scrollLines = 3
3845
)
3946

4047
type mainModel struct {
@@ -265,6 +272,7 @@ func (m mainModel) View() string {
265272
BorderForeground(lipgloss.Color("8")).Render(content)
266273
} else {
267274
// Show a thin grab line when sidebar is hidden.
275+
// Width(0) means only the border is rendered (1 char).
268276
grabLine := lipgloss.NewStyle().
269277
Width(0).
270278
Height(m.height - footerHeight - headerHeight).
@@ -505,7 +513,7 @@ func (m mainModel) handleFileTreeClick(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
505513
}
506514

507515
func (m mainModel) handleScroll(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
508-
lines := 3
516+
lines := scrollLines
509517

510518
// Check if scrolling in sidebar (file tree or search results).
511519
if zone.Get(zoneFileTree).InBounds(msg) || zone.Get(zoneSearchResults).InBounds(msg) {
@@ -538,15 +546,15 @@ func (m mainModel) handleScroll(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
538546

539547
func (m mainModel) handleSidebarDrag(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
540548
// Hide sidebar if dragged below threshold.
541-
if msg.X < 10 {
549+
if msg.X < sidebarHideWidth {
542550
m.isShowingFileTree = false
543551
m.draggingSidebar = false
544552
cmd := m.diffViewer.SetSize(m.width, m.height-footerHeight-headerHeight)
545553
return m, cmd
546554
}
547555

548556
// Clamp to reasonable bounds.
549-
minWidth := 20
557+
minWidth := sidebarMinWidth
550558
maxWidth := m.width / 2
551559
newWidth := max(minWidth, min(maxWidth, msg.X))
552560

0 commit comments

Comments
 (0)