Skip to content

Commit

Permalink
Fix #59914
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ committed Dec 18, 2024
1 parent 72f07dc commit c11bb42
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/gui/qgsshortcutsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,26 @@ void QgsShortcutsManager::shortcutDestroyed( QShortcut *shortcut )
void QgsShortcutsManager::updateActionToolTip( QAction *action, const QString &sequence )
{
QString current = action->toolTip();
// Remove the old shortcut.
const thread_local QRegularExpression rx( QStringLiteral( "\\(.*\\)" ) );
current.replace( rx, QString() );
const thread_local QRegularExpression rx( QStringLiteral( "\\((.*)\\)" ) );
// Look for the last occurrence of text inside parentheses
QRegularExpressionMatch match;
if ( current.lastIndexOf( rx, -1, &match ) != -1 )
{
// Check if it is a valid QKeySequence
bool validSequence = true;
for ( const QString &part : QKeySequence( match.captured( 1 ) ).toString().split( "," ) )
{
if ( part.trimmed().isEmpty() )
{
validSequence = false;
break;
}
}
if ( validSequence )
{
current = current.remove( match.capturedStart( 0 ), match.capturedLength( 0 ) );
}
}

if ( !sequence.isEmpty() )
{
Expand Down

0 comments on commit c11bb42

Please sign in to comment.