tdf#157114 The popup "Search Commands" should also search by sub-menu
Currently, the popup "Search Commands" only search by menu item. For example,
searching for "right" yields "Format / Align Text / Right", but searching for
"align" yields nothing.
I updated function findInMenu to search in both sub-menus and menu items. This
makes it easier to discover related actions in the same sub-menu.
Change-Id: I8aa03619c5a3db9c95b09600a80caed1e029d1af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156617
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
diff --git a/sfx2/source/commandpopup/CommandPopup.cxx b/sfx2/source/commandpopup/CommandPopup.cxx
index f4cdf92..8d68bd6 100644
--- a/sfx2/source/commandpopup/CommandPopup.cxx
+++ b/sfx2/source/commandpopup/CommandPopup.cxx
@@ -83,11 +83,11 @@ void MenuContentHandler::gatherMenuContent(
aNewContent.m_aCommandURL, m_sModuleLongName);
OUString aLabel = vcl::CommandInfoProvider::GetLabelForCommand(aCommandProperties);
aNewContent.m_aMenuLabel = aLabel;
aNewContent.m_aSearchableMenuLabel = toLower(aLabel);
if (!rMenuContent.m_aFullLabelWithPath.isEmpty())
aNewContent.m_aFullLabelWithPath = rMenuContent.m_aFullLabelWithPath + " / ";
aNewContent.m_aFullLabelWithPath += aNewContent.m_aMenuLabel;
aNewContent.m_aSearchableMenuLabel = toLower(aNewContent.m_aFullLabelWithPath);
aNewContent.m_aTooltip = vcl::CommandInfoProvider::GetTooltipForCommand(
aNewContent.m_aCommandURL, aCommandProperties, m_xFrame);
@@ -107,13 +107,16 @@ void MenuContentHandler::findInMenu(OUString const& rText,
OUString aLowerCaseText = toLower(rText);
// find submenus and menu items that start with the searched text
auto aTextStartCriterium = [](MenuContent const& rMenuContent, OUString const& rSearchText) {
return rMenuContent.m_aSearchableMenuLabel.startsWith(rSearchText);
OUString aSearchText = " / " + rSearchText;
return rMenuContent.m_aSearchableMenuLabel.indexOf(aSearchText) > 0;
};
findInMenuRecursive(m_aMenuContent, aLowerCaseText, rpCommandTreeView, rCommandList,
aTextStartCriterium);
// find submenus and menu items that contain the searched text
auto aTextAllCriterium = [](MenuContent const& rMenuContent, OUString const& rSearchText) {
return rMenuContent.m_aSearchableMenuLabel.indexOf(rSearchText) > 0;
};