Auto-Type support for T-CONV, T-REPLACE-RX, and Comments

* Close #1825 - Add full support for T-CONV and T-REPLACE-RX placeholders. Exception is support for the "raw" type in T-CONV.

* Close #5333 - Allow comment syntax to be present in the Auto-Type sequence
This commit is contained in:
Jonathan White 2020-12-24 10:58:11 -05:00
parent 813ab47e29
commit 02446af743
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
4 changed files with 135 additions and 23 deletions

View file

@ -586,8 +586,67 @@ AutoType::parseActions(const QString& entrySequence, const Entry* entry, QString
}
}
}
} else if (placeholder == "beep" || placeholder.startsWith("vkey")
|| placeholder.startsWith("appactivate")) {
} else if (placeholder.startsWith("t-conv:")) {
// Reset to the original capture to preserve case
placeholder = match.captured(3);
placeholder.replace("t-conv:", "", Qt::CaseInsensitive);
if (!placeholder.isEmpty()) {
auto sep = placeholder[0];
auto parts = placeholder.split(sep);
if (parts.size() >= 4) {
auto resolved = entry->resolveMultiplePlaceholders(parts[1]);
auto type = parts[2].toLower();
if (type == "base64") {
resolved = resolved.toUtf8().toBase64();
} else if (type == "hex") {
resolved = resolved.toUtf8().toHex();
} else if (type == "uri") {
resolved = QUrl::toPercentEncoding(resolved.toUtf8());
} else if (type == "uri-dec") {
resolved = QUrl::fromPercentEncoding(resolved.toUtf8());
} else if (type.startsWith("u")) {
resolved = resolved.toUpper();
} else if (type.startsWith("l")) {
resolved = resolved.toLower();
} else if (error) {
*error = tr("Invalid conversion type: %1").arg(type);
continue;
}
for (const QChar& ch : resolved) {
actions << QSharedPointer<AutoTypeKey>::create(ch);
}
} else if (error) {
*error = tr("Invalid conversion syntax: %1").arg(fullPlaceholder);
}
} else if (error) {
*error = tr("Invalid conversion syntax: %1").arg(fullPlaceholder);
}
} else if (placeholder.startsWith("t-replace-rx:")) {
// Reset to the original capture to preserve case
placeholder = match.captured(3);
placeholder.replace("t-replace-rx:", "", Qt::CaseInsensitive);
if (!placeholder.isEmpty()) {
auto sep = placeholder[0];
auto parts = placeholder.split(sep);
if (parts.size() >= 5) {
auto resolvedText = entry->resolveMultiplePlaceholders(parts[1]);
auto resolvedSearch = entry->resolveMultiplePlaceholders(parts[2]);
auto resolvedReplace = entry->resolveMultiplePlaceholders(parts[3]);
// Replace $<num> with \<num>s to support Qt substitutions
resolvedReplace.replace(QRegularExpression("\\$(\\d+)"), "\\\\1");
auto resolved = resolvedText.replace(QRegularExpression(resolvedSearch), resolvedReplace);
for (const QChar& ch : resolved) {
actions << QSharedPointer<AutoTypeKey>::create(ch);
}
} else if (error) {
*error = tr("Invalid conversion syntax: %1").arg(fullPlaceholder);
}
} else if (error) {
*error = tr("Invalid conversion syntax: %1").arg(fullPlaceholder);
}
} else if (placeholder == "beep" || placeholder.startsWith("vkey") || placeholder.startsWith("appactivate")
|| placeholder.startsWith("c:")) {
// Ignore these commands
} else {
// Attempt to resolve an entry attribute