fix(cortex-tui): fix scrollbar position to reflect viewport, not selection#218
Merged
fix(cortex-tui): fix scrollbar position to reflect viewport, not selection#218
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
total_items - max_visible(the actual scrollable area)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 toFileMentionStatefor proper scrollbar calculation in MentionPopup.Testing
cargo check -p cortex-tuipasses ✅cargo fmt --check -p cortex-tuipasses ✅