# HG changeset patch # User Markus Mützel # Date 1711642953 -3600 # Thu Mar 28 17:22:33 2024 +0100 # Node ID a7b65e6c541f836bf82df3037c10ef38fdfb25fd # Parent 421c45e180cef087c0e21b9c47ff887b507fd252 gui: Improve right-click menu for selected text in command window widget (bug #65518). * libgui/qterminal/libqterminal/QTerminal.cc (QTerminal::handleCustomContextMenuRequested): Improve regular expression to extract relevant part of selected text for different options of the right-click menu in the command window widget. diff -r 421c45e180ce -r a7b65e6c541f libgui/qterminal/libqterminal/QTerminal.cc --- a/libgui/qterminal/libqterminal/QTerminal.cc Thu Mar 28 16:26:44 2024 +0100 +++ b/libgui/qterminal/libqterminal/QTerminal.cc Thu Mar 28 17:22:33 2024 +0100 @@ -107,7 +107,7 @@ if (has_selected_text) { - QRegularExpression expr {"(\\w+)"}; + QRegularExpression expr {"\\b([A-Za-z_]\\w*)"}; QRegularExpressionMatch match = expr.match (selected_text); if (match.hasMatch ()) @@ -115,15 +115,22 @@ QString expr_found = match.captured (1); m_edit_selected_action->setVisible (true); - m_edit_selected_action->setText (tr ("Edit %1").arg (expr_found)); + m_edit_selected_action->setText (tr ("Edit \"%1\"").arg (expr_found)); m_edit_selected_action->setData (expr_found); m_help_selected_action->setVisible (true); - m_help_selected_action->setText (tr ("Help on %1").arg (expr_found)); + m_help_selected_action->setText (tr ("Help on \"%1\"").arg (expr_found)); m_help_selected_action->setData (expr_found); + } + + QRegularExpression expr2 {"^\\s*(\\w.*)\\s*$"}; + match = expr2.match (selected_text); + if (match.hasMatch ()) + { + QString expr_found = match.captured (1); m_doc_selected_action->setVisible (true); - m_doc_selected_action->setText (tr ("Documentation on %1") + m_doc_selected_action->setText (tr ("Documentation on \"%1\"") .arg (expr_found)); m_doc_selected_action->setData (expr_found); }