Skip to content

Commit

Permalink
Merge pull request #2348 from cooperra/patch-1
Browse files Browse the repository at this point in the history
Fix debouncing not working on first search character; add extra delay instead
  • Loading branch information
alperozturk96 authored Sep 23, 2024
2 parents 9170c37 + a7859e1 commit d6afa9f
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
private SearchView searchView;
private String searchQuery = null;
private static final int delay = 50; // If the search string does not change after $delay ms, then the search task starts.
private static final int shortStringDelay = 200; // A longer delay for short search strings.
private static final int shortStringSize = 3; // The maximum length of a short search string.
private boolean directEditRemotelyAvailable = false; // avoid using this directly, instead use: isDirectEditEnabled()

@ColorInt
Expand Down Expand Up @@ -228,8 +230,8 @@ private void queryWithHandler(@NonNull String newText) {
handler.removeCallbacksAndMessages(null);
}
delayQueryTask = new DelayQueryRunnable(newText);
// If there is only one char in the search pattern, we should start the search immediately.
handler.postDelayed(delayQueryTask, newText.length() > 1 ? delay : 0);
// If there are few chars in the search pattern, we should start the search later.
handler.postDelayed(delayQueryTask, newText.length() > shortStringSize ? delay : shortStringDelay);
}

class DelayQueryRunnable implements Runnable {
Expand Down

0 comments on commit d6afa9f

Please sign in to comment.