File tree Expand file tree Collapse file tree
main/java/com/ichi2/anki/browser
test/java/com/ichi2/anki/browser Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,6 +57,10 @@ class SearchHistory(
5757 */
5858 fun addRecent (entry : SearchHistoryEntry ): List <SearchHistoryEntry > {
5959 val updatedEntries = entries.toMutableList()
60+ if (entry.isSearchEmpty()) {
61+ Timber .d(" skipping updating history with no search" )
62+ return updatedEntries
63+ }
6064 updatedEntries.remove(entry)
6165 updatedEntries.add(0 , entry)
6266 return updatedEntries.take(maxEntries).also {
@@ -93,6 +97,12 @@ class SearchHistory(
9397 val query : String ,
9498 ) {
9599 override fun toString () = query
100+
101+ /* *
102+ * Whether there is no set search - effectively a search for the default search:
103+ * `deck:*`
104+ */
105+ fun isSearchEmpty () = query.isBlank()
96106 }
97107
98108 companion object {
Original file line number Diff line number Diff line change @@ -121,6 +121,13 @@ class SearchHistoryTest : RobolectricTest() {
121121 assertThat(history.entries.single().query, equalTo(" 1" ))
122122 }
123123
124+ @Test
125+ fun `blank entries are not persisted` () {
126+ history.addRecent(SearchHistoryEntry (" " ))
127+ history.addRecent(SearchHistoryEntry (" " ))
128+ assertThat(history.entries, empty())
129+ }
130+
124131 /* * Adds numbered entries from 1 to [count] inclusive */
125132 fun addNumberedEntries (count : Int ) =
126133 repeat(count) {
You can’t perform that action at this time.
0 commit comments