tdf#138234 Focus the frame before executing toolbar action

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 <noel.grandin@collabora.co.uk>
This commit is contained in:
Neil Roberts
2025-10-20 20:45:55 +02:00
committed by Noel Grandin
parent de5bdb5aa9
commit ea8767fe50
@@ -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;