Improved search highlighting

pull/212/head
M66B 2 years ago
parent cd150dfe41
commit 0449011951

@ -2946,7 +2946,9 @@ public class HtmlHelper {
if (node instanceof TextNode) if (node instanceof TextNode)
try { try {
TextNode tnode = (TextNode) node; TextNode tnode = (TextNode) node;
String text = Fts4DbHelper.preprocessText(tnode.getWholeText()); String whole = tnode.getWholeText();
String text = Fts4DbHelper.preprocessText(whole);
String ref = (whole.length() == text.length() ? whole : text);
Matcher result = p.matcher(text); Matcher result = p.matcher(text);
@ -2956,7 +2958,7 @@ public class HtmlHelper {
int start = result.start(1); int start = result.start(1);
int end = result.end(1); int end = result.end(1);
holder.appendText(text.substring(prev, start)); holder.appendText(ref.substring(prev, start));
Element span = document.createElement("span"); Element span = document.createElement("span");
span.attr("style", mergeStyles( span.attr("style", mergeStyles(
@ -2964,9 +2966,7 @@ public class HtmlHelper {
"font-size:larger !important;" + "font-size:larger !important;" +
"font-weight:bold !important;" + "font-weight:bold !important;" +
"background-color:" + encodeWebColor(color) + " !important")); "background-color:" + encodeWebColor(color) + " !important"));
span.text(tnode.getWholeText().length() == text.length() span.text(ref.substring(start, end));
? tnode.getWholeText().substring(start, end)
: text.substring(start, end));
holder.appendChild(span); holder.appendChild(span);
prev = end; prev = end;
@ -2976,7 +2976,7 @@ public class HtmlHelper {
return; return;
if (prev < text.length()) if (prev < text.length())
holder.appendText(text.substring(prev)); holder.appendText(ref.substring(prev));
tnode.before(holder); tnode.before(holder);
tnode.text(""); tnode.text("");

Loading…
Cancel
Save