tab: Keep selected tabs visible in overflowing tab bars - #3021
tab: Keep selected tabs visible in overflowing tab bars#3021BeratHundurel wants to merge 1 commit into
Conversation
Keep indicator and measurement helpers outside the tracked tab indices. Reveal controlled selection when tabs or the selected label change, and retry after viewport bounds are updated. Cover insertion, label replacement, viewport changes, and manual scrolling with regression tests. Implementation and tests developed with AI assistance; the fix was verified in Castle. Fixes longbridge#2531
bf43e7a to
3444949
Compare
huacnlee
left a comment
There was a problem hiding this comment.
The fixes to logical tab indices and the timing of explicit scroll requests are useful, but we do not want to introduce the behavior shown in the video that keeps the active tab visible automatically.
Users should be able to scroll the tab bar away from the active tab and leave it offscreen. Changes to tab labels, tab count, or layout should not pull the strip back to the active tab. Activating a tab and explicitly requesting that it be revealed is a separate interaction from continuously maintaining its visibility.
Please narrow this PR to #2531:
- Keep the index and layout-timing fixes so an explicit
scroll_handle.scroll_to_item(index)reliably reveals the requested tab, including a newly inserted tab. - Remove the automatic reveal policy based on the selected index, tab count, selected label, or viewport changes.
track_scroll()should not implicitly opt applications into that policy. - If a layout retry is needed, associate it with the caller's explicit scroll request and preserve its target, rather than requesting the active tab on every bounds change.
- Update the tests to verify explicit scroll requests and preservation of manual scrolling, rather than requiring the active tab to stay visible.
I also reproduced two regressions with additional tests: closing an unselected trailing tab, or moving the entire tab bar down by 20 px without changing its viewport size, resets a manually chosen horizontal offset from -100 px to -4 px. Both tests pass on the base revision and fail on this PR. These illustrate why we should keep this change focused on the explicit scrolling API.
Fixes #2531.
When the tab bar overflows, opening or selecting a tab can leave it hidden or partially clipped until another interaction.
This change keeps scroll indices aligned with logical tabs, reveals the selected tab when the list or its label changes, and retries scrolling after viewport bounds change. Manual scrolling remains unaffected when selection and layout are unchanged.
Verification
Reproduction
The recording below demonstrates the issue in an app I’m developing with GPUI Kit.
Before
before.mp4
After
after.mp4
Checklist
cargo runfor story tests related to the changes.