Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Update custom button tab index when removing intermediate tabs without changing current selected tab (Widgets) #22292

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions spyder/widgets/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,19 @@ def tabInserted(self, index):
# Set close button
self.setTabButton(index, self.close_btn_side, close_button)

def tabRemoved(self, index):
"""Actions to take when a tab is removed."""
# A tab removal makes the following ones to change their `index` (`-1`)
# Following that, there is a need to update the `index` attribute that
# the custom close button instances have. Otherwise, for example on the
# Editor, an `IndexError` can be raised.
# See spyder-ide/spyder#22033
for i in range(index, self.count()):
close_btn: CloseTabButton = self.tabButton(i, self.close_btn_side)

if close_btn:
close_btn.index = i


class BaseTabs(QTabWidget):
"""TabWidget with context menu and corner widgets"""
Expand Down