Skip to content

Fix height calculations using lipgloss.Height for accurate layout#62

Open
clobrano wants to merge 2 commits intomainfrom
claude/fix-scrolling-issue-FHbGf
Open

Fix height calculations using lipgloss.Height for accurate layout#62
clobrano wants to merge 2 commits intomainfrom
claude/fix-scrolling-issue-FHbGf

Conversation

@clobrano
Copy link
Copy Markdown
Owner

@clobrano clobrano commented Apr 8, 2026

Summary

This PR improves the accuracy of component height calculations in the TUI by using lipgloss.Height() instead of manual newline counting. This ensures proper handling of styled text with padding and accounts for footer text wrapping on small screens.

Key Changes

  • model.go: Replaced hardcoded height calculation (7 lines) with dynamic measurement of actual rendered component heights

    • Now calls m.renderSections() and m.renderFooter() to measure their actual heights
    • Uses lipgloss.Height() to accurately account for padding and styling
    • Removes empirically-determined spacing constant that could cause layout issues on different screen sizes
  • view.go: Standardized height calculations to use lipgloss.Height() consistently

    • Replaced manual newline counting (strings.Count(sectionsBar, "\n") + 1) with lipgloss.Height()
    • Updated footer height calculation to use lipgloss.Height() which already accounts for vertical padding
    • Removed manual padding adjustment (+2) that was previously needed for manual calculations

Implementation Details

  • The change makes the layout calculation more robust by measuring actual rendered output rather than relying on hardcoded assumptions
  • This is particularly important for the footer which may wrap text on smaller screens, causing the hardcoded 7-line calculation to be inaccurate
  • Using lipgloss.Height() consistently across both files ensures the height calculations in model.go and view.go remain synchronized

https://claude.ai/code/session_01TRR9WnvruHoCMM4FKRXDfH

claude added 2 commits April 8, 2026 07:19
The footer height was double-counted in view.go: lipgloss.Render() already
includes padding in the output string, but footerHeight added +2 again for
padding. This caused the content area to be trimmed too aggressively.

Additionally, model.go used a fixed constant (m.height - 7) for the task list
height, which didn't account for footer text wrapping on small screens. Now
both view.go and model.go measure actual rendered heights using lipgloss.Height,
ensuring the task list gets the correct available space regardless of screen
size or footer wrapping.

https://claude.ai/code/session_01TRR9WnvruHoCMM4FKRXDfH
Two bugs in the scrolling logic:

1. Small screen mode hardcoded 2 lines per task (visibleHeight / 2), but
   each task actually renders 1 + len(narrowViewFields) lines. With the
   default 2 narrow fields (due, tags), tasks take 3 lines each. This
   caused the scroll to think more tasks fit than actually do, leaving
   the selected task outside the visible area.

2. Normal screen mode (updateScroll) completely ignored the scrollBuffer
   setting. It only ensured the cursor row was barely visible with no
   surrounding context. Now it calculates buffer zones in line-space
   above and below the cursor, keeping scrollBuffer tasks visible on
   each side.

https://claude.ai/code/session_01TRR9WnvruHoCMM4FKRXDfH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants