From 34bb7a7c7f690c69f64ace7367e936e036a9058f Mon Sep 17 00:00:00 2001 From: marcusDenslow Date: Sat, 25 Apr 2026 22:00:44 +0200 Subject: [PATCH] fix: correct scroll height estimates and improve order selection visibility The scroll-to-item calculations used wrong item heights (7/5 instead of 9/7) and ignored the 5-line title header offset, causing the viewport to under-scroll. Selected order cards now light up in accent color for better visibility across terminal themes. Co-Authored-By: Claude Opus 4.6 --- pkg/tui/account.go | 30 ++++++++++++++++++++++-------- pkg/tui/account_orders.go | 5 +++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/pkg/tui/account.go b/pkg/tui/account.go index 2047b0c..6c06d5b 100644 --- a/pkg/tui/account.go +++ b/pkg/tui/account.go @@ -92,23 +92,35 @@ func (m Model) getAccountDetailContent() string { // scrollToAccountDetailItem adjusts the viewport scroll to keep the selected item visible. // Follows the reference pattern: cursor moves immediately, viewport catches up. +// +// Each sub-page has a title header (e.g. "Order History" + margin + newlines) that +// pushes the first item down. headerOffset accounts for those lines. itemHeight +// must match the actual rendered card height including borders, padding, and the +// inter-card gap ("\n" between cards in the view function). func (m Model) scrollToAccountDetailItem() Model { - var itemHeight, itemCount, selectedIndex int + var itemHeight, itemCount, selectedIndex, headerOffset int switch { case m.account.orderViewState == 1: - itemHeight = 7 - if m.heightContainer < 25 { - itemHeight = 5 + // "Order History" + MarginBottom(2) + "\n\n" = ~5 header lines + headerOffset = 5 + if m.heightContainer >= 25 { + // border(2) + vPadding(2) + content(~4) + gap(1) = 9 + itemHeight = 9 + } else { + // border(2) + content(~4) + gap(1) = 7 + itemHeight = 7 } itemCount = len(m.Orders) selectedIndex = m.account.orderCursor case m.account.addressListFocused: - itemHeight = 5 + headerOffset = 5 + itemHeight = 6 itemCount = len(m.SavedAddresses) selectedIndex = m.account.addressCursor case m.account.cardListFocused: - itemHeight = 4 + headerOffset = 5 + itemHeight = 5 itemCount = len(m.SavedCards) selectedIndex = m.account.cardCursor default: @@ -119,13 +131,15 @@ func (m Model) scrollToAccountDetailItem() Model { return m } - targetY := (selectedIndex * itemHeight) + 2 + targetY := headerOffset + (selectedIndex * itemHeight) vpH := m.account.detailViewport.Height offset := m.account.detailViewport.YOffset + // If item is above viewport, scroll up to show it if targetY < offset { - m.account.detailViewport.SetYOffset(targetY - 2) + m.account.detailViewport.SetYOffset(targetY) } + // If item is below viewport, scroll down to show it if targetY+itemHeight > offset+vpH { m.account.detailViewport.SetYOffset(targetY - vpH + itemHeight) } diff --git a/pkg/tui/account_orders.go b/pkg/tui/account_orders.go index 881e517..2e2dbbb 100644 --- a/pkg/tui/account_orders.go +++ b/pkg/tui/account_orders.go @@ -51,7 +51,12 @@ func (m Model) buildOrderCard(order models.Order, boxWidth int, isSelected bool, // Order header line: "Order #123" left, "Jan 02 2026 PAID" right nameStyle := m.theme.TextAccent().Bold(true) + // When selected, item preview text uses accent color instead of dim + // so the whole card "lights up" — much more visible than border color alone dimStyle := m.theme.TextDim() + if isSelected { + dimStyle = m.theme.TextAccent() + } statusStyle := m.theme.TextHighlight().Bold(true)