From afbdcef805dc572ee2f3a79a52fde99818715bd4 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 28 Feb 2026 10:13:52 +0200 Subject: refactor(ui): break up large functions in ui package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Go/MEDIUM task (UUID d8b51046): several functions exceeded 50 lines. Extract logical sections into focused helpers: renderTaskDetail() (238→20 lines): delegates to detailStyles(), renderDetailFieldRows() + per-field helpers (Priority, Tags, Due, Project, Recur), renderDetailDescription(), renderDetailAnnotations(), renderDetailFooter(). handleDetailFieldEdit() (128→32 lines): uses switch + shared activation helpers (activatePriorityEdit, activateDueEdit, activateTagsEdit, activateProjectEdit, activateRecurEdit, handleDetailDynamicFields). handleEnterOrEdit() (120→42 lines): reuses the same shared helpers from handlers.go; adds a taskStr closure to remove repetitive nil-guards. View() (82→25 lines): extracts appendInlineInputOverlay() that iterates the active editing overlays and appends the focused widget to the layout. Also fix hardcoded Description blink index (was always 9); introduce detailDescriptionFieldIndex() which returns 9 or 10 depending on whether the task has a Recurrence field, matching the dynamic render position. Clarify that Annotations are read-only in the detail view. Co-Authored-By: Claude Sonnet 4.6 --- internal/ui/table.go | 94 ++++++++++++++++------------------------------------ 1 file changed, 29 insertions(+), 65 deletions(-) (limited to 'internal/ui/table.go') diff --git a/internal/ui/table.go b/internal/ui/table.go index 97011ff..893f08f 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -558,7 +558,7 @@ func (m *Model) handleDescEditDone(msg descEditDoneMsg) (tea.Model, tea.Cmd) { // Reload and start blinking m.reload() - return m, m.startDetailBlink(9) // Description field index + return m, m.startDetailBlink(m.detailDescriptionFieldIndex()) } return m, nil @@ -618,7 +618,6 @@ func (m *Model) handleBlinkMsg() (tea.Model, tea.Cmd) { // View renders the table UI. func (m Model) View() string { if m.showHelp { - // Update help content before rendering m.updateHelpContent() return m.renderHelpScreen() } @@ -634,70 +633,35 @@ func (m Model) View() string { m.statusLine(), ) if m.cellExpanded { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.expandedCellView(), - ) - } - if m.annotating { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.annotateInput.View(), - ) - } - if m.dueEditing { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.dueView(true), - ) - } - if m.prioritySelecting { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.priorityView(true), - ) - } - if m.descEditing { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.descInput.View(), - ) + view = lipgloss.JoinVertical(lipgloss.Left, view, m.expandedCellView()) } - if m.tagsEditing { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.tagsInput.View(), - ) - } - if m.recurEditing { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.recurInput.View(), - ) - } - if m.projEditing { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.projInput.View(), - ) - } - if m.filterEditing { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.filterInput.View(), - ) - } - if m.addingTask { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.addInput.View(), - ) - } - if m.searching { - view = lipgloss.JoinVertical(lipgloss.Left, - view, - m.searchInput.View(), - ) + return m.appendInlineInputOverlay(view) +} + +// appendInlineInputOverlay appends whichever active inline-editing widget +// (annotate, due, priority, desc, tags, recur, project, filter, add, search) +// should be displayed below the table. At most one is active at a time. +func (m Model) appendInlineInputOverlay(view string) string { + type overlay struct { + active bool + widget string + } + overlays := []overlay{ + {m.annotating, m.annotateInput.View()}, + {m.dueEditing, m.dueView(true)}, + {m.prioritySelecting, m.priorityView(true)}, + {m.descEditing, m.descInput.View()}, + {m.tagsEditing, m.tagsInput.View()}, + {m.recurEditing, m.recurInput.View()}, + {m.projEditing, m.projInput.View()}, + {m.filterEditing, m.filterInput.View()}, + {m.addingTask, m.addInput.View()}, + {m.searching, m.searchInput.View()}, + } + for _, o := range overlays { + if o.active { + view = lipgloss.JoinVertical(lipgloss.Left, view, o.widget) + } } return view } -- cgit v1.2.3