fix: correct scroll height estimates and improve order selection visibility
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
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 <noreply@anthropic.com>
This commit is contained in:
@@ -92,23 +92,35 @@ func (m Model) getAccountDetailContent() string {
|
|||||||
|
|
||||||
// scrollToAccountDetailItem adjusts the viewport scroll to keep the selected item visible.
|
// scrollToAccountDetailItem adjusts the viewport scroll to keep the selected item visible.
|
||||||
// Follows the reference pattern: cursor moves immediately, viewport catches up.
|
// 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 {
|
func (m Model) scrollToAccountDetailItem() Model {
|
||||||
var itemHeight, itemCount, selectedIndex int
|
var itemHeight, itemCount, selectedIndex, headerOffset int
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case m.account.orderViewState == 1:
|
case m.account.orderViewState == 1:
|
||||||
itemHeight = 7
|
// "Order History" + MarginBottom(2) + "\n\n" = ~5 header lines
|
||||||
if m.heightContainer < 25 {
|
headerOffset = 5
|
||||||
itemHeight = 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)
|
itemCount = len(m.Orders)
|
||||||
selectedIndex = m.account.orderCursor
|
selectedIndex = m.account.orderCursor
|
||||||
case m.account.addressListFocused:
|
case m.account.addressListFocused:
|
||||||
itemHeight = 5
|
headerOffset = 5
|
||||||
|
itemHeight = 6
|
||||||
itemCount = len(m.SavedAddresses)
|
itemCount = len(m.SavedAddresses)
|
||||||
selectedIndex = m.account.addressCursor
|
selectedIndex = m.account.addressCursor
|
||||||
case m.account.cardListFocused:
|
case m.account.cardListFocused:
|
||||||
itemHeight = 4
|
headerOffset = 5
|
||||||
|
itemHeight = 5
|
||||||
itemCount = len(m.SavedCards)
|
itemCount = len(m.SavedCards)
|
||||||
selectedIndex = m.account.cardCursor
|
selectedIndex = m.account.cardCursor
|
||||||
default:
|
default:
|
||||||
@@ -119,13 +131,15 @@ func (m Model) scrollToAccountDetailItem() Model {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
targetY := (selectedIndex * itemHeight) + 2
|
targetY := headerOffset + (selectedIndex * itemHeight)
|
||||||
vpH := m.account.detailViewport.Height
|
vpH := m.account.detailViewport.Height
|
||||||
offset := m.account.detailViewport.YOffset
|
offset := m.account.detailViewport.YOffset
|
||||||
|
|
||||||
|
// If item is above viewport, scroll up to show it
|
||||||
if targetY < offset {
|
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 {
|
if targetY+itemHeight > offset+vpH {
|
||||||
m.account.detailViewport.SetYOffset(targetY - vpH + itemHeight)
|
m.account.detailViewport.SetYOffset(targetY - vpH + itemHeight)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// Order header line: "Order #123" left, "Jan 02 2026 PAID" right
|
||||||
nameStyle := m.theme.TextAccent().Bold(true)
|
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()
|
dimStyle := m.theme.TextDim()
|
||||||
|
if isSelected {
|
||||||
|
dimStyle = m.theme.TextAccent()
|
||||||
|
}
|
||||||
|
|
||||||
statusStyle := m.theme.TextHighlight().Bold(true)
|
statusStyle := m.theme.TextHighlight().Bold(true)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user