diff options
author | Noah Haasis <haasis_noah@yahoo.de> | 2021-10-18 19:21:42 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-10-30 17:13:25 +0330 |
commit | 05aeff1c4d3b5a86b4ca0f73e9f0736aef84800a (patch) | |
tree | d1cdf0b19f80278c2a1ccda098fce0c36f1dce17 /Userland/Libraries | |
parent | de2e95b2789d742df436b848412814b8cbcdf0fb (diff) | |
download | serenity-05aeff1c4d3b5a86b4ca0f73e9f0736aef84800a.zip |
LibGUI: Focus next tab after closing active tab
Focus the next tab after closing the currently active tab.
If the tab being closed is the last one then the new last
tab is active.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGUI/TabWidget.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp index 88fe7977a4..c0220f0681 100644 --- a/Userland/Libraries/LibGUI/TabWidget.cpp +++ b/Userland/Libraries/LibGUI/TabWidget.cpp @@ -56,10 +56,17 @@ void TabWidget::add_widget(const StringView& title, Widget& widget) void TabWidget::remove_widget(Widget& widget) { VERIFY(widget.parent() == this); - if (active_widget() == &widget) - activate_next_tab(); - m_tabs.remove_first_matching([&widget](auto& entry) { return &widget == entry.widget; }); + auto tab_index = m_tabs.find_if([&widget](auto& entry) { return &widget == entry.widget; }).index(); + + auto is_active = active_widget() == &widget; + m_tabs.remove(tab_index); remove_child(widget); + + if (is_active && m_tabs.size() > 0) { + auto next_tab_index = tab_index >= m_tabs.size() ? m_tabs.size() - 1 : tab_index; + set_tab_index(next_tab_index); + } + update_focus_policy(); if (on_tab_count_change) on_tab_count_change(m_tabs.size()); |