comparison libgui/qterminal/libqterminal/QTerminal.cc @ 33269:28c7f3195d3a

All Command Window right-click menu to search documentation for multi-word pattern (bug #65518) * QTerminal.cc (handleCustomContextMenuRequested): Use a different regexp to trim selected text of leading and trailing whitespace and use that for the Documentation menu item.
author Rik <rik@octave.org>
date Thu, 28 Mar 2024 11:26:47 -0700
parents 421c45e180ce
children 65d2a1f70155
comparison
equal deleted inserted replaced
33267:95c195edc257 33269:28c7f3195d3a
105 } 105 }
106 #endif 106 #endif
107 107
108 if (has_selected_text) 108 if (has_selected_text)
109 { 109 {
110 QRegularExpression expr {"(\\w+)"}; 110 // Find first word in selected text, trim everything else
111 QRegularExpression expr {"^\\s*(\\w+)"};
111 QRegularExpressionMatch match = expr.match (selected_text); 112 QRegularExpressionMatch match = expr.match (selected_text);
112 113
113 if (match.hasMatch ()) 114 if (match.hasMatch ())
114 { 115 {
115 QString expr_found = match.captured (1); 116 QString expr_found = match.captured (1);
120 121
121 m_help_selected_action->setVisible (true); 122 m_help_selected_action->setVisible (true);
122 m_help_selected_action->setText (tr ("Help on %1").arg (expr_found)); 123 m_help_selected_action->setText (tr ("Help on %1").arg (expr_found));
123 m_help_selected_action->setData (expr_found); 124 m_help_selected_action->setData (expr_found);
124 125
126 // Grab all of selected text, but trim leading/trailing whitespace
127 expr.setPattern ("^\\s*(\\w.*)\\s*$");
128 match = expr.match (selected_text);
129 expr_found = match.captured (1);
125 m_doc_selected_action->setVisible (true); 130 m_doc_selected_action->setVisible (true);
126 m_doc_selected_action->setText (tr ("Documentation on %1") 131 m_doc_selected_action->setText (tr ("Documentation on %1")
127 .arg (expr_found)); 132 .arg (expr_found));
128 m_doc_selected_action->setData (expr_found); 133 m_doc_selected_action->setData (expr_found);
129 } 134 }