Heighlight text improvements

pull/210/head
M66B 3 years ago
parent 2ede17a7d0
commit 1c32eee3bc

@ -2960,11 +2960,12 @@ public class HtmlHelper {
return ssb; return ssb;
} }
static Document highlightSearched(Context context, Document document, String query) { static void highlightSearched(Context context, Document document, String query) {
try {
int color = Helper.resolveColor(context, R.attr.colorHighlight); int color = Helper.resolveColor(context, R.attr.colorHighlight);
query = Normalizer.normalize(query, Normalizer.Form.NFKD) query = Fts4DbHelper.preprocessText(query);
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
// TODO breakText
// TODO: fix highlighting pre processed text // TODO: fix highlighting pre processed text
List<String> word = new ArrayList<>(); List<String> word = new ArrayList<>();
@ -2972,9 +2973,9 @@ public class HtmlHelper {
for (String w : query.trim().split("\\s+")) for (String w : query.trim().split("\\s+"))
if (w.length() > 1 && (w.startsWith("+") || w.startsWith("-"))) { if (w.length() > 1 && (w.startsWith("+") || w.startsWith("-"))) {
if (w.startsWith("+")) if (w.startsWith("+"))
plus.add(w.substring(1)); plus.add(Pattern.quote(w.substring(1)));
} else } else
word.add(w); word.add(Pattern.quote(w));
int flags = Pattern.DOTALL | Pattern.CASE_INSENSITIVE; int flags = Pattern.DOTALL | Pattern.CASE_INSENSITIVE;
List<Pattern> pat = new ArrayList<>(); List<Pattern> pat = new ArrayList<>();
@ -2989,8 +2990,7 @@ public class HtmlHelper {
if (node instanceof TextNode) if (node instanceof TextNode)
try { try {
TextNode tnode = (TextNode) node; TextNode tnode = (TextNode) node;
String text = Normalizer.normalize(tnode.getWholeText(), Normalizer.Form.NFKD) String text = Fts4DbHelper.preprocessText(tnode.getWholeText());
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
Matcher result = p.matcher(text); Matcher result = p.matcher(text);
@ -3030,8 +3030,9 @@ public class HtmlHelper {
public void tail(Node node, int depth) { public void tail(Node node, int depth) {
} }
}, document); }, document);
} catch (Throwable ex) {
return document; Log.e(ex);
}
} }
static Document markText(Document document) { static Document markText(Document document) {

Loading…
Cancel
Save