From ef9543c4bc43f5847d7c087e6ac61cc5c0b48a1b Mon Sep 17 00:00:00 2001 From: Dhruv Thakur Date: Thu, 25 Jul 2024 07:56:38 +0200 Subject: [PATCH] feat: remove spacing in full screen compact mode Spacing needs to be 1 for compact mode when the context pane is visible. This is due to a quirk in how the list bubble renders. The list renders with 1 extra line in this case, which pushes the whole view up, causing UI inconsistencies. Handling this case by investigating the state of the model has been frustratingly futile, so spacing stays at 1 for this view for now. --- internal/ui/initial.go | 8 ++++++-- internal/ui/update.go | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/internal/ui/initial.go b/internal/ui/initial.go index 74d0d56..cc28117 100644 --- a/internal/ui/initial.go +++ b/internal/ui/initial.go @@ -17,9 +17,13 @@ func InitialModel(db *sql.DB, config Config) model { tlSelItemStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(config.TaskListColor)) var taskList list.Model + var spacing int + if config.ShowContext { + spacing = 1 + } switch config.ListDensity { case Compact: - taskList = list.New(taskItems, newListDelegate(lipgloss.Color(config.TaskListColor), false, 1), taskSummaryWidth, defaultListHeight) + taskList = list.New(taskItems, newListDelegate(lipgloss.Color(config.TaskListColor), false, spacing), taskSummaryWidth, defaultListHeight) case Spacious: taskList = list.New(taskItems, newListDelegate(lipgloss.Color(config.TaskListColor), true, 1), taskSummaryWidth, defaultListHeight) } @@ -45,7 +49,7 @@ func InitialModel(db *sql.DB, config Config) model { var archivedTaskList list.Model switch config.ListDensity { case Compact: - archivedTaskList = list.New(archivedTaskItems, newListDelegate(lipgloss.Color(config.ArchivedTaskListColor), false, 1), taskSummaryWidth, defaultListHeight) + archivedTaskList = list.New(archivedTaskItems, newListDelegate(lipgloss.Color(config.ArchivedTaskListColor), false, spacing), taskSummaryWidth, defaultListHeight) case Spacious: archivedTaskList = list.New(archivedTaskItems, newListDelegate(lipgloss.Color(config.ArchivedTaskListColor), true, 1), taskSummaryWidth, defaultListHeight) } diff --git a/internal/ui/update.go b/internal/ui/update.go index 92f2902..824e537 100644 --- a/internal/ui/update.go +++ b/internal/ui/update.go @@ -807,6 +807,11 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var tlDel list.DefaultDelegate var atlDel list.DefaultDelegate + var spacing int + if m.cfg.ShowContext { + spacing = 1 + } + switch m.cfg.ListDensity { case Compact: tlDel = newListDelegate(lipgloss.Color(m.cfg.TaskListColor), true, 1) @@ -815,13 +820,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.cfg.ListDensity = Spacious case Spacious: - tlDel = newListDelegate(lipgloss.Color(m.cfg.TaskListColor), false, 1) - atlDel = newListDelegate(lipgloss.Color(m.cfg.ArchivedTaskListColor), false, 1) + tlDel = newListDelegate(lipgloss.Color(m.cfg.TaskListColor), false, spacing) + atlDel = newListDelegate(lipgloss.Color(m.cfg.ArchivedTaskListColor), false, spacing) m.cfg.ListDensity = Compact } m.taskList.SetDelegate(tlDel) m.archivedTaskList.SetDelegate(atlDel) + for i, li := range m.taskList.Items() { t, ok := li.(types.Task) if ok { @@ -860,6 +866,17 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { listHeight = m.terminalHeight - h - h3 - 1 } + if m.cfg.ListDensity == Compact { + var spacing int + if m.cfg.ShowContext { + spacing = 1 + } + tlDel := newListDelegate(lipgloss.Color(m.cfg.TaskListColor), false, spacing) + atlDel := newListDelegate(lipgloss.Color(m.cfg.ArchivedTaskListColor), false, spacing) + m.taskList.SetDelegate(tlDel) + m.archivedTaskList.SetDelegate(atlDel) + } + m.taskList.SetHeight(listHeight) m.archivedTaskList.SetHeight(listHeight)