Skip to content

fix(cortex-tui): fix scrollbar position to reflect viewport, not selection#218

Merged
echobt merged 1 commit intomasterfrom
fix/scrollbar-viewport-position
Jan 27, 2026
Merged

fix(cortex-tui): fix scrollbar position to reflect viewport, not selection#218
echobt merged 1 commit intomasterfrom
fix/scrollbar-viewport-position

Conversation

@echobt
Copy link
Contributor

@echobt echobt commented Jan 27, 2026

Summary

This PR fixes the scrollbar behavior in dropdown menus that was introduced in PR #216. The scrollbar was incorrectly using the selected item index as its position, causing the scrollbar thumb to jump around based on the highlighted item rather than showing the actual viewport position.

Problem

When scrolling through a long list of commands (e.g., after /usage), the scrollbar didn't properly indicate the viewport position. This made it unclear to users that there were items above/below the visible area.

Solution

Changed the scrollbar state to use:

  • scrollable_range = total_items - max_visible (the actual scrollable area)
  • position = scroll_offset (the current viewport position)

This makes the scrollbar properly indicate which portion of the list is currently visible, matching standard scrollbar behavior.

Changes

Fixed scrollbar position calculation in:

  • AutocompletePopup (slash commands like /help, /clear, /share, /usage)
  • MentionPopup (file mentions with @)
  • ScrollableDropdown (generic reusable component)
  • SelectionList (generic selection lists)

Added max_visible() getter to FileMentionState for proper scrollbar calculation in MentionPopup.

Testing

  • cargo check -p cortex-tui passes ✅
  • cargo fmt --check -p cortex-tui passes ✅
  • All widget tests pass ✅
  • All mentions tests pass ✅

…ction

The scrollbar in dropdown menus was incorrectly using the selected item
index as its position, which caused the scrollbar thumb to jump around
based on the highlighted item rather than showing the actual viewport
position.

This fix changes the scrollbar state to use:
- scrollable_range = total_items - max_visible (the actual scrollable area)
- position = scroll_offset (the current viewport position)

This makes the scrollbar properly indicate which portion of the list is
currently visible, so when scrolling past items like /usage, the user
can see that there are more items above that are now hidden.

Fixed in:
- AutocompletePopup (slash commands)
- MentionPopup (file mentions)
- ScrollableDropdown (generic component)
- SelectionList (generic selection)

Added max_visible() getter to FileMentionState for proper scrollbar
calculation.

Fixes scrollbar behavior from PR #216.
@echobt echobt merged commit 9d16b2b into master Jan 27, 2026
2 of 12 checks passed
@echobt echobt deleted the fix/scrollbar-viewport-position branch January 27, 2026 12:37
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