epub阅读添加搜索

This commit is contained in:
DelLevin-Home
2026-07-01 05:03:58 +08:00
parent 0af1af7f1a
commit d5bec0fe9b
7 changed files with 573 additions and 9 deletions

View File

@@ -18,18 +18,31 @@ mixin _ProgressMixin on State<ReaderScreen> {
Timer? get progressDebouncer;
set progressDebouncer(Timer? v);
Map<int, int> get chapterPageCounts;
void updateProgressDebounced() {
progressDebouncer?.cancel();
progressDebouncer = Timer(const Duration(milliseconds: 150), () {
if (!mounted) return;
if (isWebViewLoading) return;
final pageInChapterStr =
'${currentPageInChapter + 1}/$totalPagesInChapter';
final totalChapters = bookSession.spine.length;
if (displayProgress != pageInChapterStr) {
// 用当前章节页数估算全书页数
final avgPages = totalPagesInChapter > 0 ? totalPagesInChapter : 1;
final estimatedTotalPages = avgPages * totalChapters;
// 估算绝对页码 = 已读章节数 * 平均每章页数 + 当前页
final estimatedAbsolutePage =
currentSpineItemIndex * avgPages + currentPageInChapter + 1;
final pageStr = totalChapters > 0
? '$estimatedAbsolutePage/$estimatedTotalPages'
: '${currentPageInChapter + 1}/$totalPagesInChapter';
if (displayProgress != pageStr) {
setState(() {
displayProgress = pageInChapterStr;
displayProgress = pageStr;
});
}
});