From c11bb42cf3d09041ed76c81b5f9eadf8d692407b Mon Sep 17 00:00:00 2001 From: Yoann Quenach de Quivillic Date: Wed, 18 Dec 2024 08:40:08 +0100 Subject: [PATCH] Fix #59914 --- src/gui/qgsshortcutsmanager.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/gui/qgsshortcutsmanager.cpp b/src/gui/qgsshortcutsmanager.cpp index 8cb5d8287e2d..7001e4bc3d0c 100644 --- a/src/gui/qgsshortcutsmanager.cpp +++ b/src/gui/qgsshortcutsmanager.cpp @@ -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() ) {