only highlight alphanumeric chars

This commit is contained in:
Daniel Gultsch 2018-05-03 13:57:13 +02:00
parent 9625f191c3
commit 5e1cbf8514
2 changed files with 22 additions and 2 deletions

View file

@ -1007,8 +1007,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
} }
} }
public void setHighlightedTerm(List<String> term) { public void setHighlightedTerm(List<String> terms) {
this.highlightedTerm = term; this.highlightedTerm = terms == null ? null : StylingHelper.filterHighlightedWords(terms);
} }
public interface OnQuoteListener { public interface OnQuoteListener {

View file

@ -47,6 +47,7 @@ import android.text.style.TypefaceSpan;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -99,6 +100,25 @@ public class StylingHelper {
} }
} }
public static List<String> filterHighlightedWords(List<String> terms) {
List<String> words = new ArrayList<>();
for(String term : terms) {
if (!FtsUtils.isKeyword(term)) {
StringBuilder builder = new StringBuilder();
for (int codepoint, i = 0; i < term.length(); i += Character.charCount(codepoint)) {
codepoint = term.codePointAt(i);
if (Character.isLetterOrDigit(codepoint)) {
builder.append(Character.toChars(codepoint));
}
}
if (builder.length() > 0) {
words.add(builder.toString());
}
}
}
return words;
}
private static void highlight(final Context context, final Editable editable, String needle, boolean dark) { private static void highlight(final Context context, final Editable editable, String needle, boolean dark) {
final int length = needle.length(); final int length = needle.length();
String string = editable.toString(); String string = editable.toString();