Преглед изворни кода

fix(search): 从书籍详情返回后保留搜索关键词与结果列表

仅输入关键词点进书架已有书籍时,committedQuery 为空,Initialize 重放会清空搜索状态;扩展会话存活判断为 committedQuery/query/results,避免返回后回到空白搜索框。Refs #2284
HapeLee пре 1 месец
родитељ
комит
ec06342f92
1 измењених фајлова са 8 додато и 5 уклоњено
  1. 8 5
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

+ 8 - 5
app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@@ -412,11 +412,14 @@ class SearchViewModel(
             syncScopeState()
             syncScopeState()
         }
         }
 
 
-        // When the ViewModel already holds a non-empty committed query,
-        // it means a search session is in progress or completed.
-        // This happens when returning from BookInfo — the LaunchedEffect
-        // re-fires but we must not wipe the existing results.
-        val hasActiveSearch = _uiState.value.committedQuery.isNotEmpty()
+        // When the ViewModel already holds a keyword (committed or only typed)
+        // or visible results, a search session is still alive. This happens when
+        // returning from BookInfo — the LaunchedEffect re-fires but we must not
+        // wipe the keyword, the source results or the bookshelf hint list.
+        val state = _uiState.value
+        val hasActiveSearch = state.committedQuery.isNotEmpty() ||
+            state.query.isNotEmpty() ||
+            state.results.isNotEmpty()
         if (isSameRequest && hasActiveSearch) return
         if (isSameRequest && hasActiveSearch) return
 
 
         clearSearchResults()
         clearSearchResults()