Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7859e1f authored by Robbie Cooper's avatar Robbie Cooper
Browse files

Use a longer debounce delay for short search strings

This gives the user more time to type in their whole query before a search blocks the main thread.

Searches for short strings often have many results that aren't really useful to the user. They also take much longer to process.

This commit increases the debounce delay to 200ms for short strings three characters long or less. Longer strings still have the 50ms delay. Hopefully, this is a good balance between avoiding slowdowns for short strings and providing a snappy interactive experience for long strings.
parent 869b2cc5
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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
@@ -228,7 +230,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
                    handler.removeCallbacksAndMessages(null);
                }
                delayQueryTask = new DelayQueryRunnable(newText);
                handler.postDelayed(delayQueryTask, delay);
                // 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 {