diff options
author | Thialfihar <thi@thialfihar.org> | 2014-05-14 19:54:20 +0200 |
---|---|---|
committer | Thialfihar <thi@thialfihar.org> | 2014-05-16 11:38:12 +0200 |
commit | ab81d8903a92e1f80105f223a727d75b94754769 (patch) | |
tree | c88f971360b3f9f1c1b55d42b2923dcc5716230f /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter | |
parent | 9025de2b74c18d45b7e1853964e8caa653db7432 (diff) | |
download | open-keychain-ab81d8903a92e1f80105f223a727d75b94754769.tar.gz open-keychain-ab81d8903a92e1f80105f223a727d75b94754769.tar.bz2 open-keychain-ab81d8903a92e1f80105f223a727d75b94754769.zip |
Support mutliple search words and highlight them
For the regex matching it would be smart to sort the words by length,
so the longest matches come first. This only matters for queries with
words containing parts of each other, which is an unlikely event and
even then it doesn't break anything.
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/HighlightQueryCursorAdapter.java | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/HighlightQueryCursorAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/HighlightQueryCursorAdapter.java index fd7a2dc30..4a37a9a3a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/HighlightQueryCursorAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/HighlightQueryCursorAdapter.java @@ -49,9 +49,9 @@ public abstract class HighlightQueryCursorAdapter extends CursorAdapter { Spannable highlight = Spannable.Factory.getInstance().newSpannable(text); if (mCurQuery != null) { - Pattern pattern = Pattern.compile("(?i)" + mCurQuery); + Pattern pattern = Pattern.compile("(?i)(" + mCurQuery.trim().replaceAll("\\s+", "|") + ")"); Matcher matcher = pattern.matcher(text); - if (matcher.find()) { + while (matcher.find()) { highlight.setSpan( new ForegroundColorSpan(mContext.getResources().getColor(R.color.emphasis)), matcher.start(), |