From f80a46d073941ac93bcf3ef9df72818b4cd2738e Mon Sep 17 00:00:00 2001 From: HapeLee <63206378+HapeLee@users.noreply.github.com> Date: Thu, 11 Jun 2026 00:47:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=A1=B5=E8=BF=94=E5=9B=9E=E6=97=B6=E4=B8=A2=E5=A4=B1=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. MainNavigator: 从 BookInfo 进入 ReadBook 时保留栈中历史, 返回路径恢复为 ReadBook → BookInfo → Search → Home 2. SearchViewModel: initialize() 检查 committedQuery 是否为空, 已有活跃搜索会话时跳过 clearSearchResults(),避免 LaunchedEffect 在 Navigation3 entry 重新进入 composition 时 清空搜索结果 --- .../java/io/legado/app/ui/book/search/SearchViewModel.kt | 9 +++++++-- app/src/main/java/io/legado/app/ui/main/MainNavigator.kt | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 9dc6fea46..71024211f 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -317,8 +317,13 @@ class SearchViewModel( } syncScopeState() - // Always reset search state so the screen starts clean, - // regardless of whether the ViewModel was retained by navigation. + // 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() + if (hasActiveSearch) return + clearSearchResults() val initKey = key?.trim().orEmpty() diff --git a/app/src/main/java/io/legado/app/ui/main/MainNavigator.kt b/app/src/main/java/io/legado/app/ui/main/MainNavigator.kt index 6934f7b46..b73997706 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainNavigator.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainNavigator.kt @@ -48,7 +48,10 @@ object MainNavigator { is MainRouteCache, MainRouteBookCacheManage, is MainRouteReadBook -> { - if (currentRoute == MainRouteHome) { + if ( + currentRoute == MainRouteHome || + currentRoute is MainRouteBookInfo + ) { backStack.add(route) } else { backStack.clear()