diff --git a/runners/webshortcuts/webshortcutrunner.cpp b/runners/webshortcuts/webshortcutrunner.cpp index 37e0aff17..6de3ac04a 100644 --- a/runners/webshortcuts/webshortcutrunner.cpp +++ b/runners/webshortcuts/webshortcutrunner.cpp @@ -105,13 +105,23 @@ void WebshortcutRunner::configurePrivateBrowsingActions() void WebshortcutRunner::match(Plasma::RunnerContext &context) { const QString term = context.query(); - const int delimIndex = term.indexOf(m_delimiter); - if (delimIndex == -1 || delimIndex == term.length() - 1) { - return; + const static QRegularExpression bangRegex(QStringLiteral("!([^ ]+).*")); + const static QRegularExpression normalRegex(QStringLiteral("^([^ ]+)%1").arg(QRegularExpression::escape(m_delimiter))); + const auto bangMatch = bangRegex.match(term); + QString key; + QString rawQuery = term; + + if (bangMatch.hasMatch()) { + key = bangMatch.captured(1); + rawQuery = rawQuery.remove(rawQuery.indexOf(key) - 1, key.size() + 1); + } else { + const auto normalMatch = normalRegex.match(term); + if (normalMatch.hasMatch()) { + key = normalMatch.captured(0); + rawQuery = rawQuery.mid(key.length()); + } } - - const QString key = term.left(delimIndex); - if (key == m_lastFailedKey) { + if (key.isEmpty() || key == m_lastFailedKey) { return; // we already know it's going to suck ;) } @@ -120,7 +130,7 @@ void WebshortcutRunner::match(Plasma::RunnerContext &context) // filtering if (m_lastKey == key) { m_filterBeforeRun = true; - m_match.setText(i18n("Search %1 for %2", m_lastProvider, term.mid(delimIndex + 1))); + m_match.setText(i18n("Search %1 for %2", m_lastProvider, rawQuery)); context.addMatch(m_match); return; } diff --git a/runners/webshortcuts/webshortcutrunner.h b/runners/webshortcuts/webshortcutrunner.h index 8da6dc600..19538f9ce 100644 --- a/runners/webshortcuts/webshortcutrunner.h +++ b/runners/webshortcuts/webshortcutrunner.h @@ -44,6 +44,7 @@ class WebshortcutRunner : public Plasma::AbstractRunner QString m_lastFailedKey; QString m_lastKey; QString m_lastProvider; + QRegularExpression m_regex; KServiceAction m_privateAction; };