From da714f771d2a164aca529e72207c80409b38d7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20De=20Canni=C3=A8re?= Date: Thu, 10 Mar 2022 12:18:28 +0100 Subject: [PATCH] LibGUI: Make only the targeted tab of TabWidget respond to double click Previously, when double clicking on the tab bar, all tabs would respond to the double click even if they weren't clicked on. This issue, for example, prevented renaming of individual tabs in Spreadsheet and instead asked the user to rename all tabs one by one. --- Userland/Libraries/LibGUI/TabWidget.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp index f9f6e23aa9..26e7a9f90e 100644 --- a/Userland/Libraries/LibGUI/TabWidget.cpp +++ b/Userland/Libraries/LibGUI/TabWidget.cpp @@ -632,15 +632,19 @@ void TabWidget::context_menu_event(ContextMenuEvent& context_menu_event) } } -void TabWidget::doubleclick_event(MouseEvent&) +void TabWidget::doubleclick_event(MouseEvent& mouse_event) { - for (auto& tab : m_tabs) { - if (auto* widget = tab.widget) { + for (size_t i = 0; i < m_tabs.size(); ++i) { + auto button_rect = this->button_rect(i); + if (!button_rect.contains(mouse_event.position())) + continue; + if (auto* widget = m_tabs[i].widget) { deferred_invoke([this, widget] { if (on_double_click) on_double_click(*widget); }); } + return; } }