# HG changeset patch # User Markus Mützel # Date 1711720429 -3600 # Node ID 65d2a1f701559b6bdea2532b744080072579e45b # Parent 28c7f3195d3afcb943a4913fd72524594036c78c gui: Right-click menu for selected text in command window widget (bug #65518). * libgui/qterminal/libqterminal/QTerminal.cc (QTerminal::handleCustomContextMenuRequested): Discard any non-word characters at start of selected string (not just whitespace) for options in context menu. Use double-quotes around matched strings from selection in context menu. Make sure there is a match for the used regular expression for the "Documentation" option before using it. diff -r 28c7f3195d3a -r 65d2a1f70155 libgui/qterminal/libqterminal/QTerminal.cc --- a/libgui/qterminal/libqterminal/QTerminal.cc Thu Mar 28 11:26:47 2024 -0700 +++ b/libgui/qterminal/libqterminal/QTerminal.cc Fri Mar 29 14:53:49 2024 +0100 @@ -108,7 +108,7 @@ if (has_selected_text) { // Find first word in selected text, trim everything else - QRegularExpression expr {"^\\s*(\\w+)"}; + QRegularExpression expr {"(\\w+)"}; QRegularExpressionMatch match = expr.match (selected_text); if (match.hasMatch ()) @@ -116,19 +116,24 @@ 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); + } - // Grab all of selected text, but trim leading/trailing whitespace - expr.setPattern ("^\\s*(\\w.*)\\s*$"); - match = expr.match (selected_text); - expr_found = match.captured (1); + // Grab all of selected text, but trim leading non-word characters + // and trailing whitespace + expr.setPattern ("(\\w.*)\\s*$"); + match = expr.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); }