diff --git a/runners/katesessions/katesessions.h b/runners/katesessions/katesessions.h --- a/runners/katesessions/katesessions.h +++ b/runners/katesessions/katesessions.h @@ -43,7 +43,7 @@ KDirWatch* m_sessionWatch = nullptr; QString m_sessionsFolderPath; QStringList m_sessions; - const QLatin1String m_triggerWord = QLatin1String("kate"); + const QLatin1String m_triggerWord = QLatin1String("kate "); }; #endif diff --git a/runners/katesessions/katesessions.cpp b/runners/katesessions/katesessions.cpp --- a/runners/katesessions/katesessions.cpp +++ b/runners/katesessions/katesessions.cpp @@ -41,8 +41,6 @@ Plasma::RunnerSyntax s(QStringLiteral("kate :q:"), i18n("Finds Kate sessions matching :q:.")); addSyntax(s); - setDefaultSyntax(Plasma::RunnerSyntax(QStringLiteral("kate"), - i18n("Lists all the Kate editor sessions in your account."))); m_sessionsFolderPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kate/sessions"); @@ -56,9 +54,7 @@ loadSessions(); } -KateSessions::~KateSessions() -{ -} +KateSessions::~KateSessions() = default; void KateSessions::loadSessions() { @@ -71,37 +67,28 @@ } m_sessions = sessions; + suspendMatching(m_sessions.isEmpty()); } void KateSessions::match(Plasma::RunnerContext &context) { QString term = context.query(); - if (term.length() < 3 || m_sessions.isEmpty() || !context.isValid()) { - return; - } + // Kate writes sessions as desktop actions in the local .desktop file => // they are already available from the "Applications" Runner and in the normal launcher - if (!term.startsWith(m_triggerWord, Qt::CaseInsensitive)) { + // this plugin only handles syntaxes like: kate + if (!term.startsWith(m_triggerWord, Qt::CaseInsensitive) || !context.isValid()) { return; } - bool listAll = false; - if (term.trimmed().compare(m_triggerWord, Qt::CaseInsensitive) == 0) { - listAll = true; - term.clear(); - } else if (term.at(4) == QLatin1Char(' ')) { - term = term.remove(m_triggerWord, Qt::CaseInsensitive).trimmed(); - } else { - // Prevent results for queries like "katee" - return; - } + term = term.remove(m_triggerWord, Qt::CaseInsensitive).trimmed(); for (const QString &session: qAsConst(m_sessions)) { - if (listAll || session.contains(term, Qt::CaseInsensitive)) { + if (session.contains(term, Qt::CaseInsensitive)) { Plasma::QueryMatch match(this); match.setType(Plasma::QueryMatch::ExactMatch); - match.setRelevance(session.compare(term, Qt::CaseInsensitive) == 0 ? 1 : 0.8); - match.setIconName(m_triggerWord); + match.setRelevance((float) term.length() / (float) session.length()); + match.setIconName(QStringLiteral("kate")); match.setData(session); match.setText(session); match.setSubtext(i18n("Open Kate Session"));