Modern Apps git

← Modern-Apps.git

maps: keep results listed while the next search runs (#mapsearch)

Commit
14366178f53c39f1cb3c26836747929abbd45558
Author
Vayun Mathur <[email protected]>
When
2026-11-13 20:05 UTC (22 days ago)
Parents
ca750d0
Symptom: searching "takes forever". Part of what made it feel that way
was the search sheet itself: every keystroke set `searching`, and
SearchUiState.phase let Searching win over a non-empty result list, so
the rows collapsed to a spinner on each character and came back only
after the debounce plus the lookup. The list visibly blinked per
keystroke, and because the phase is also MapSheets' `contentKey`, the
sheet re-keyed (and re-learned its height ceiling) on every
Searching <-> Results flip.

Change: Searching now only wins over an EMPTY list. While a search is
in flight, the previous query's rows stay on screen until the new rows
replace them (search-as-you-type: the previous rows are nearly always
a superset of the next query's). An empty list still shows the
spinner while a search runs and "No results" only once it finished, so
the false-empty-state fix the phase table exists for is unchanged.

User-visible effect: no spinner flash between keystrokes; the sheet
height no longer jumps while typing.

Verified: SearchUiStateTest updated (stale rows during a search are
Results; the empty-while-running and empty-after-finish cases keep
their assertions); module tests run in the container build.

Diff

maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.ktindex a33ab450ca..db6b7c04bb 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapsUiContract.kt@@ -29,14 +29,20 @@ data class SearchUiState(      * and after it found nothing — so a running search rendered "No results found". Naming the      * phases makes the distinction impossible to collapse again, and makes the ordering      * (searching wins over empty) a property of the state instead of the order of `when` branches.+     *+     * Searching only wins over an EMPTY list. While the user types, every keystroke starts a new+     * search, and the list used to collapse to a spinner for each one and come back a moment+     * later — the results visibly blinked on every character, and the sheet re-keyed its height+     * on every flip (the phase is its content key). The previous query's rows are almost always+     * a superset of the next one's, so they stay up until the new rows replace them.      */     val phase: SearchPhase         get() = when {             query.length < 2 && recents.isNotEmpty() -> SearchPhase.Recents             query.length < 2 -> SearchPhase.Idle+            results.isNotEmpty() -> SearchPhase.Results             searching -> SearchPhase.Searching-            results.isEmpty() -> SearchPhase.Empty-            else -> SearchPhase.Results+            else -> SearchPhase.Empty         } } @@ -48,13 +54,13 @@ enum class SearchPhase {     /** Nothing typed, but there are recent queries worth offering. */     Recents, -    /** A search is in flight — including its debounce window. */+    /** A search is in flight — including its debounce window — and nothing is listed yet. */     Searching,      /** The search finished and found nothing. */     Empty, -    /** The search finished and found something. */+    /** There are rows to list: the finished search's, or the previous query's while the next runs. */     Results, } 
maps/src/test/java/com/vayunmathur/maps/util/SearchUiStateTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/SearchUiStateTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/SearchUiStateTest.ktindex 51904ac0df..32213f03f3 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/SearchUiStateTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/SearchUiStateTest.kt@@ -39,13 +39,14 @@ class SearchUiStateTest {     }      /**-     * Stale results from the previous query are still on screen while the next one runs. Showing-     * them beats blanking the list, but the phase must say a search is in flight.+     * Stale results from the previous query stay on screen while the next one runs. Blanking the+     * list to a spinner on every keystroke made the results blink per character and re-keyed the+     * sheet's height each time; the new rows simply replace the old ones when they arrive.      */     @Test-    fun `searching wins over stale results`() {+    fun `stale results stay listed while the next search runs`() {         val state = SearchUiState(query = "ferry b", results = results, searching = true)-        assertEquals(SearchPhase.Searching, state.phase)+        assertEquals(SearchPhase.Results, state.phase)     }      /** Below the two-character floor nothing is searched, so recents are the useful thing. */