Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma Workspace
Commits
84b54791
Commit
84b54791
authored
Oct 11, 2020
by
Alexander Lohnau
💬
Browse files
Allow syntax for DuckDuckGo bangs in Webshortcuts
FEATURE: 423003
FIXED-IN: 5.21
parent
68306ef1
Changes
2
Hide whitespace changes
Inline
Side-by-side
runners/webshortcuts/webshortcutrunner.cpp
View file @
84b54791
...
...
@@ -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
;
}
...
...
runners/webshortcuts/webshortcutrunner.h
View file @
84b54791
...
...
@@ -44,6 +44,7 @@ class WebshortcutRunner : public Plasma::AbstractRunner
QString
m_lastFailedKey
;
QString
m_lastKey
;
QString
m_lastProvider
;
QRegularExpression
m_regex
;
KServiceAction
m_privateAction
;
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment