Merge pull request #2348 from cooperra/patch-1

Fix debouncing not working on first search character; add extra delay instead
This commit is contained in:
Alper Öztürk 2024-09-23 09:29:48 +02:00 committed by GitHub
commit d6afa9f30a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,6 +48,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
private SearchView searchView; private SearchView searchView;
private String searchQuery = null; 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 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() private boolean directEditRemotelyAvailable = false; // avoid using this directly, instead use: isDirectEditEnabled()
@ColorInt @ColorInt
@ -228,8 +230,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
handler.removeCallbacksAndMessages(null); handler.removeCallbacksAndMessages(null);
} }
delayQueryTask = new DelayQueryRunnable(newText); delayQueryTask = new DelayQueryRunnable(newText);
// If there is only one char in the search pattern, we should start the search immediately. // If there are few chars in the search pattern, we should start the search later.
handler.postDelayed(delayQueryTask, newText.length() > 1 ? delay : 0); handler.postDelayed(delayQueryTask, newText.length() > shortStringSize ? delay : shortStringDelay);
} }
class DelayQueryRunnable implements Runnable { class DelayQueryRunnable implements Runnable {