Skip to content

tab: Fix explicit scrolling to newly added tabs - #3021

Merged
huacnlee merged 3 commits into
longbridge:mainfrom
BeratHundurel:codex/fix-tab-bar-scroll-position
Sep 10, 2026
Merged

tab: Fix explicit scrolling to newly added tabs#3021
huacnlee merged 3 commits into
longbridge:mainfrom
BeratHundurel:codex/fix-tab-bar-scroll-position

Conversation

@BeratHundurel

Copy link
Copy Markdown
Contributor

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

  • Added regression coverage for insertion, label replacement, viewport changes, and manual scrolling.
  • All 15 tab tests, formatting, and Clippy pass.

Reproduction

The recording below demonstrates the issue in an app I’m developing with GPUI Kit.

Before

before.mp4

After

after.mp4

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes.
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific)

@BeratHundurel
BeratHundurel force-pushed the codex/fix-tab-bar-scroll-position branch from bf43e7a to 3444949 Compare September 8, 2026 20:00

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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
@BeratHundurel
BeratHundurel force-pushed the codex/fix-tab-bar-scroll-position branch from 3444949 to d575a66 Compare September 9, 2026 23:32
@BeratHundurel

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. I narrowed this PR to the explicit scrolling API.

  • Removed automatic reveal behavior based on selection, tab count, label changes, and viewport changes.
  • Kept the logical index and layout fixes so explicit scroll_handle.scroll_to_item(index) calls reliably reveal the requested tab, including newly inserted tabs.
  • Added regression coverage for explicit scrolling and preserving manual offsets when selection, labels, tab count, or tab-bar position changes.

@huacnlee huacnlee changed the title tab: Keep selected tabs visible in overflowing tab bars tab: Fix explicit scrolling to newly added tabs Sep 10, 2026
@huacnlee
huacnlee enabled auto-merge (squash) September 10, 2026 07:08
@huacnlee
huacnlee disabled auto-merge September 10, 2026 07:09
huacnlee and others added 2 commits September 10, 2026 15:13
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
@huacnlee
huacnlee enabled auto-merge (squash) September 10, 2026 07:18

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@huacnlee
huacnlee merged commit 47d25c8 into longbridge:main Sep 10, 2026
8 checks passed
linruohan pushed a commit to linruohan/gpui-component that referenced this pull request Sep 11, 2026
Fixes longbridge#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

- Added regression coverage for insertion, label replacement, viewport
changes, and manual scrolling.
- All 15 tab tests, formatting, and Clippy pass.

## Reproduction

The recording below demonstrates the issue in an app I’m developing with
GPUI Kit.

### Before


https://github.com/user-attachments/assets/552ccc9a-cb76-47dc-a6a8-c3c4ef2f1fab

### After


https://github.com/user-attachments/assets/22437b6e-ef50-45b8-8b69-5f38edf68578

## Checklist

- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [x] Passed `cargo run` for story tests related to the changes.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)

---------

Co-authored-by: Jason Lee <huacnlee@gmail.com>
Co-authored-by: Codex <codex@openai.com>
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.

scrollhandle.scroll_to_item() is not work right in Tabs, when use segmented, pill or underline

2 participants