From ea8767fe503384eeabda0d008acf748086d8ef66 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 17 Oct 2025 21:48:54 +0200 Subject: [PATCH] tdf#138234 Focus the frame before executing toolbar action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a toolbar is floating then when a button is clicked on it the toolbar window will end up taking focus. This is kind of confusing if the button does an action such as inserting a table row. In that case you want the cursor to be visible in the document and to be able to immediately start typing in the new row. Note that despite the description in the bug report I think this is a general problem on all platforms and with all toolbar buttons. For example the cursor “disappears” in the same surprising way if you press the button to insert a footnote. To fix the problem this patch just makes it pass the focus to the toolbar’s frame before dispatching the command. This is similar to what is already done in the code for the font toolbar to handle when a new font is selected. Change-Id: Ifd941fb4ae295c57d465f4c8ff798913ce4a14c8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192649 Tested-by: Jenkins Reviewed-by: Noel Grandin --- framework/source/uielement/generictoolbarcontroller.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/framework/source/uielement/generictoolbarcontroller.cxx b/framework/source/uielement/generictoolbarcontroller.cxx index 0db12a966a23..f500adce46c8 100644 --- a/framework/source/uielement/generictoolbarcontroller.cxx +++ b/framework/source/uielement/generictoolbarcontroller.cxx @@ -149,6 +149,12 @@ void SAL_CALL GenericToolbarController::execute( sal_Int16 KeyModifier ) aCommandURL = m_aCommandURL; xDispatch = pIter->second; + + // tdf#138234 If this toolbar is a floating window then + // clicking on a button probably took the window focus. Let’s + // give it back to the toolbar’s frame. + if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() ) + m_xFrame->getContainerWindow()->setFocus(); } css::util::URL aTargetURL;