@@ -1102,10 +1102,16 @@ QKeyCombination QKeySequencePrivate::decodeString(QString accel, QKeySequence::S
1102
1102
return Qt::Key_unknown;
1103
1103
#endif
1104
1104
1105
+ int singlePlus = -1 ;
1105
1106
qsizetype i = 0 ;
1106
1107
qsizetype lastI = 0 ;
1107
1108
while ((i = sl.indexOf (u' +' , i + 1 )) != -1 ) {
1108
- const QStringView sub = QStringView{sl}.mid (lastI, i - lastI + 1 );
1109
+ QStringView sub = QStringView{ sl }.mid (lastI, i - lastI + 1 );
1110
+ while (sub.size () > 1 && sub.at (0 ) == QLatin1Char (' ' )) {
1111
+ sub = sub.mid (1 );
1112
+ ++lastI;
1113
+ }
1114
+
1109
1115
// If we get here the shortcuts contains at least one '+'. We break up
1110
1116
// along the following strategy:
1111
1117
// Meta+Ctrl++ ( "Meta+", "Ctrl+", "+" )
@@ -1117,33 +1123,49 @@ QKeyCombination QKeySequencePrivate::decodeString(QString accel, QKeySequence::S
1117
1123
// Only '+' can have length 1.
1118
1124
if (sub.size () == 1 ) {
1119
1125
// Make sure we only encounter a single '+' at the end of the accel
1120
- if (accel. lastIndexOf (u ' + ' ) != accel. size ()- 1 )
1126
+ if (singlePlus >= 0 )
1121
1127
return Qt::Key_unknown;
1128
+ singlePlus = lastI;
1122
1129
} else {
1123
- // Identify the modifier
1124
- bool validModifier = false ;
1125
- for (int j = 0 ; j < modifs.size (); ++j) {
1126
- const QModifKeyName &mkf = modifs.at (j);
1127
- if (sub == mkf.name ) {
1128
- ret |= mkf.qt_key ;
1129
- validModifier = true ;
1130
- break ; // Shortcut, since if we find an other it would/should just be a dup
1130
+
1131
+ const auto identifyModifier = [&](QStringView sub) {
1132
+ for (int j = 0 ; j < modifs.size (); ++j) {
1133
+ const QModifKeyName &mkf = modifs.at (j);
1134
+ if (sub == mkf.name ) {
1135
+ ret |= mkf.qt_key ;
1136
+ return true ; // Shortcut, since if we find another it would/should just be a dup
1137
+ }
1131
1138
}
1132
- }
1139
+ return false ;
1140
+ };
1133
1141
1142
+ bool validModifier = identifyModifier (sub);
1143
+
1144
+ if (!validModifier) {
1145
+ // Try harder with slower code that trims spaces
1146
+ const QString cleanedSub = sub.toString ().remove (QLatin1Char (' ' ));
1147
+ validModifier = identifyModifier (cleanedSub);
1148
+ }
1134
1149
if (!validModifier)
1135
1150
return Qt::Key_unknown;
1136
1151
}
1137
1152
lastI = i + 1 ;
1138
1153
}
1139
1154
1140
- qsizetype p = accel.lastIndexOf (u' +' , accel.size () - 2 ); // -2 so that Ctrl++ works
1155
+ qsizetype p = accel.lastIndexOf (u' +' , singlePlus > 0 ? singlePlus - 1 : accel.size () - 1 );
1141
1156
QStringView accelRef (accel);
1142
1157
if (p > 0 )
1143
1158
accelRef = accelRef.mid (p + 1 );
1144
1159
1160
+ while (accelRef.size () > 1 && accelRef.at (0 ) == QLatin1Char (' ' ))
1161
+ accelRef = accelRef.mid (1 );
1162
+ while (accelRef.size () > 1 && accelRef.endsWith (QLatin1Char (' ' )))
1163
+ accelRef.chop (1 );
1164
+
1145
1165
int fnum = 0 ;
1146
- if (accelRef.size () == 1 ) {
1166
+ if (accelRef.isEmpty ())
1167
+ return Qt::Key_unknown;
1168
+ else if (accelRef.size () == 1 ) {
1147
1169
#if defined(Q_OS_APPLE)
1148
1170
int qtKey = qtkeyForAppleSymbol (accelRef.at (0 ));
1149
1171
if (qtKey != -1 ) {
0 commit comments