Mercurial > octave
changeset 33270:65d2a1f70155
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.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Fri, 29 Mar 2024 14:53:49 +0100 |
parents | 28c7f3195d3a |
children | 59ee9d370307 |
files | libgui/qterminal/libqterminal/QTerminal.cc |
diffstat | 1 files changed, 13 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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); }