Skip to content

tab_switcher: Fix bug where selected index after closing tab did not match pane's active item#44006

Merged
dinocosta merged 5 commits intomainfrom
tab-switcher-close-item-fix
Dec 3, 2025
Merged

tab_switcher: Fix bug where selected index after closing tab did not match pane's active item#44006
dinocosta merged 5 commits intomainfrom
tab-switcher-close-item-fix

Conversation

@dinocosta
Copy link
Member

@dinocosta dinocosta commented Dec 2, 2025

Whenever an item is removed using the Tab Switcher, the list of matches is automatically updated, which can lead to the order of the elements being updated and changing in comparison to what the user was previously seeing. Unfortunately this can lead to a situation where the selected index, since it wasn't being updated, would end up in a different item than the one that was actually active in the pane.

This Pull Request updates the handling of the PaneEvent::RemovedItem event so that the TabSwitcherDelegate.selected_index field is automatically updated to match the pane's new active item.

Seeing as this is being updated, the test_close_preserves_selected_position test is also removed, as it no longer makes sense with the current implementation. I believe a better user experience would be to actually not update the order of the matches, simply removing the ones that no longer exist, and keep the selected index position, but will tackle that in a different Pull Request.

Closes #44005

Release Notes:

  • Fixed a bug with the tab switcher where, after closing a tab, the selected entry would not match the pane's active item

Whenever the `CloseSelectedItem` action was dispatched and the selected
index item's was closed, it was possible for the pane's item to end up
different than the new selected index in the `TabSwitcher`. This commit
reacts to the `PaneEvent::ActivateItem` event to ensure that the
`TabSwitcherDelegate.selected_index` matches the newly active item of
its pane.
Update the existing test, `test_close_selected_item`, to ensure that,
after clsoing an item, the newly activated item's entry will also be
selected in the tab switcher to match the pane's state.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 2, 2025
@dinocosta dinocosta self-assigned this Dec 2, 2025
Update `TabSwitcherDelegate.subscribe_to_updates` in order to only sync
the selected index when handling a `PaneEvent::RemovedItem` event
instead of `PaneEvent::ActivateItem`, as the latter event is triggered
everytime the user navigates to a different entry in the Tab Swithcer,
while the former event is triggered only when an item is removed from
the tab switcher, which is exactly when the bug manifests itself.

This commit also removes the `test_close_preserves_selected_position`
test, as it was added at a time when the list of matches in the tab
switcher was not updated when an item was removed. With the current
implementation, I believe it no longer makes sense, as we simply end up
in a situation where the selected index does not match the pane's active
item. I do believe that not having the list update automatically and
move entries around is a better experience, and will try to get another
Pull Request in the future to implement this and re-add the test.
@dinocosta dinocosta marked this pull request as ready for review December 3, 2025 10:11
@dinocosta dinocosta merged commit 6b46a71 into main Dec 3, 2025
24 checks passed
@dinocosta dinocosta deleted the tab-switcher-close-item-fix branch December 3, 2025 17:12
HactarCE added a commit that referenced this pull request Dec 3, 2025
…44101)

Closes #43171

Previously the tab switcher only subscribed to events from a single pane
so closing tabs in other panes wouldn't cause the tab switcher to
update. This PR changes that so the tab switcher subscribes to the whole
workspace and thus updates when tabs in other panes are closed.

It also modifies the work in #44006 to sync selected index across the
whole workspace instead of just the original pane in the case of the
all-panes tab switcher.

Release Notes:

- Fixed all-panes tab switcher not updating in response to changes in
other panes
AlpSha pushed a commit to AlpSha/zed that referenced this pull request Dec 5, 2025
…ed-industries#44101)

Closes zed-industries#43171

Previously the tab switcher only subscribed to events from a single pane
so closing tabs in other panes wouldn't cause the tab switcher to
update. This PR changes that so the tab switcher subscribes to the whole
workspace and thus updates when tabs in other panes are closed.

It also modifies the work in zed-industries#44006 to sync selected index across the
whole workspace instead of just the original pane in the case of the
all-panes tab switcher.

Release Notes:

- Fixed all-panes tab switcher not updating in response to changes in
other panes
CherryWorm pushed a commit to CherryWorm/zed that referenced this pull request Dec 16, 2025
…match pane's active item (zed-industries#44006)

Whenever an item is removed using the Tab Switcher, the list of matches
is automatically updated, which can lead to the order of the elements
being updated and changing in comparison to what the user was previously
seeing. Unfortunately this can lead to a situation where the selected
index, since it wasn't being updated, would end up in a different item
than the one that was actually active in the pane.

This Pull Request updates the handling of the `PaneEvent::RemovedItem`
event so that the `TabSwitcherDelegate.selected_index` field is
automatically updated to match the pane's new active item.

Seeing as this is being updated, the
`test_close_preserves_selected_position` test is also removed, as it no
longer makes sense with the current implementation. I believe a better
user experience would be to actually not update the order of the
matches, simply removing the ones that no longer exist, and keep the
selected index position, but will tackle that in a different Pull
Request.

Closes zed-industries#44005 

Release Notes:

- Fixed a bug with the tab switcher where, after closing a tab, the
selected entry would not match the pane's active item
CherryWorm pushed a commit to CherryWorm/zed that referenced this pull request Dec 16, 2025
…ed-industries#44101)

Closes zed-industries#43171

Previously the tab switcher only subscribed to events from a single pane
so closing tabs in other panes wouldn't cause the tab switcher to
update. This PR changes that so the tab switcher subscribes to the whole
workspace and thus updates when tabs in other panes are closed.

It also modifies the work in zed-industries#44006 to sync selected index across the
whole workspace instead of just the original pane in the case of the
all-panes tab switcher.

Release Notes:

- Fixed all-panes tab switcher not updating in response to changes in
other panes
someone13574 pushed a commit to someone13574/zed that referenced this pull request Dec 16, 2025
…match pane's active item (zed-industries#44006)

Whenever an item is removed using the Tab Switcher, the list of matches
is automatically updated, which can lead to the order of the elements
being updated and changing in comparison to what the user was previously
seeing. Unfortunately this can lead to a situation where the selected
index, since it wasn't being updated, would end up in a different item
than the one that was actually active in the pane.

This Pull Request updates the handling of the `PaneEvent::RemovedItem`
event so that the `TabSwitcherDelegate.selected_index` field is
automatically updated to match the pane's new active item.

Seeing as this is being updated, the
`test_close_preserves_selected_position` test is also removed, as it no
longer makes sense with the current implementation. I believe a better
user experience would be to actually not update the order of the
matches, simply removing the ones that no longer exist, and keep the
selected index position, but will tackle that in a different Pull
Request.

Closes zed-industries#44005 

Release Notes:

- Fixed a bug with the tab switcher where, after closing a tab, the
selected entry would not match the pane's active item
someone13574 pushed a commit to someone13574/zed that referenced this pull request Dec 16, 2025
…ed-industries#44101)

Closes zed-industries#43171

Previously the tab switcher only subscribed to events from a single pane
so closing tabs in other panes wouldn't cause the tab switcher to
update. This PR changes that so the tab switcher subscribes to the whole
workspace and thus updates when tabs in other panes are closed.

It also modifies the work in zed-industries#44006 to sync selected index across the
whole workspace instead of just the original pane in the case of the
all-panes tab switcher.

Release Notes:

- Fixed all-panes tab switcher not updating in response to changes in
other panes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tab Switcher – Weird state after closing item

1 participant