From cba28685512d2fdd39eab1afc6857004bad86466 Mon Sep 17 00:00:00 2001 From: stefan-niedermann Date: Thu, 23 Jan 2020 10:07:57 +0100 Subject: [PATCH] #550 In-note-search doesn't jump to occurrence of searchstring - Fix Exception when wrapping from last to first occurrence --- .../android/fragment/BaseNoteFragment.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java index cdf96b34..e67675fa 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/BaseNoteFragment.java @@ -229,11 +229,19 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo if (currentVisibility != View.VISIBLE) { colorWithText(""); searchQuery = ""; - if(prev != null) { prev.hide(); } - if(next != null) { next.hide(); } + if (prev != null) { + prev.hide(); + } + if (next != null) { + next.hide(); + } } else { - if(prev != null) { prev.show(); } - if(next != null) { next.show(); } + if (prev != null) { + prev.show(); + } + if (next != null) { + next.show(); + } } oldVisibility = currentVisibility; @@ -287,8 +295,12 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo String currentContent = getContent().toLowerCase(); int indexOfNewText = indexOfNth(currentContent, searchQuery.toLowerCase(), 0, occurrence); if (indexOfNewText <= 0) { - // Search term not in text - occurrence = 1; + // Search term is not n times in text + // Go back to first search result + if (occurrence != 1) { + occurrence = 1; + jumpToOccurrence(); + } return; } String textUntilFirstOccurrence = currentContent.substring(0, indexOfNewText);