Skip to content

Commit

Permalink
Fix crash when searching and lowercase snippet differs from input sni…
Browse files Browse the repository at this point in the history
…ppet.
  • Loading branch information
cody-signal committed Mar 28, 2023
1 parent 80b9e4e commit 149955e
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ private void updateSnippetWithStyles(long id, @NonNull CharSequence body, @NonNu
for (String query : queries) {
int foundIndex = lowerBody.indexOf(query.toLowerCase());
if (foundIndex != -1) {
int snippetStart = Math.max(0, Math.max(lowerBody.lastIndexOf(' ', foundIndex - 5) + 1, foundIndex - 15));
int lastSpace = lowerBody.indexOf(' ', foundIndex + 30);
int snippetEnd = Math.min(lowerBody.length(), lastSpace > 0 ? Math.min(lastSpace, foundIndex + 40) : foundIndex + 40);
int snippetStart = Math.max(0, Math.max(TextUtils.lastIndexOf(styledBody,' ', foundIndex - 5) + 1, foundIndex - 15));
int lastSpace = TextUtils.indexOf(styledBody, ' ', foundIndex + 30);
int snippetEnd = Math.min(styledBody.length(), lastSpace > 0 ? Math.min(lastSpace, foundIndex + 40) : foundIndex + 40);

return new SpannableStringBuilder().append(snippetStart > 0 ? SNIPPET_WRAP : "")
.append(styledBody.subSequence(snippetStart, snippetEnd))
Expand Down

0 comments on commit 149955e

Please sign in to comment.