From 3e0b3ee03718007d82185918b9a7b28eb0a7ab52 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Wed, 28 Dec 2022 21:39:55 +0530 Subject: [PATCH] compare lastSearch with searchText. --- .../e/apps/search/SearchFragment.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt index 9e9d26b49..e995e3e5a 100644 --- a/app/src/main/java/foundation/e/apps/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/search/SearchFragment.kt @@ -148,15 +148,18 @@ class SearchFragment : override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { searchView?.run { /* - * Only scroll back to 0 position for a new search. - * - * If we are getting new results from livedata for the old search query, - * do not scroll to top as the user may be scrolling to see already - * populated results. - */ - if (lastSearch != query?.toString()) { + * Only scroll back to 0 position for a new search. + * + * If we are getting new results from livedata for the old search query, + * do not scroll to top as the user may be scrolling to see already + * populated results. + * + * Compare lastSearch with searchText to avoid falsely updating to + * current query text even before submitting the new search. + */ + if (lastSearch != searchText) { recyclerView?.scrollToPosition(0) - lastSearch = query.toString() + lastSearch = searchText } } } -- GitLab