Fix search result styling for formatting and query highlighting.

This commit is contained in:
Cody Henthorne
2023-03-24 15:49:09 -04:00
parent f53679f24a
commit ba2d005b2a
2 changed files with 3 additions and 3 deletions

View File

@@ -321,7 +321,7 @@ public class SearchRepository {
BodyRangeList.Builder builder = BodyRangeList.newBuilder();
for (BodyRangeList.BodyRange range : bodyRanges.getRangesList()) {
int adjustedStart = range.getStart() - startIndex + startOffset;
if (adjustedStart >= 0 && adjustedStart + range.getLength() <= cleanSnippet.length()) {
if (adjustedStart >= 0 && adjustedStart + range.getLength() <= bodySnippet.length()) {
builder.addRanges(range.toBuilder().setStart(adjustedStart).build());
}
}

View File

@@ -70,12 +70,12 @@ public class SearchUtil {
throw new InvalidParameterException("match mode must be STRICT or MATCH_ALL: " + matchMode);
}
CharacterStyle[] styles = styleFactory.createStyles();
for (Pair<Integer, Integer> range : ranges) {
CharacterStyle[] styles = styleFactory.createStyles();
for (CharacterStyle style : styles) {
List<Annotation> annotations = SpoilerAnnotation.getSpoilerAnnotations(spanned, range.first(), range.second());
if (annotations.isEmpty()) {
spanned.setSpan(style, range.first(), range.second(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
spanned.setSpan(style, range.first(), range.second(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}