From 6003038055d833321ff5b5664b9e21a9165246ff Mon Sep 17 00:00:00 2001 From: ypl <7353755@gmail.com> Date: Mon, 23 Nov 2026 15:41:21 +0200 Subject: [PATCH] =?UTF-8?q?=D7=9E=D7=A4=D7=A8=D7=A9=D7=99=D7=9D:=20=D7=94?= =?UTF-8?q?=D7=A6=D7=92=D7=AA=20=D7=94=D7=9E=D7=99=D7=A7=D7=95=D7=9D=20?= =?UTF-8?q?=D7=94=D7=A0=D7=95=D7=9B=D7=97=D7=99=20=D7=91=D7=9B=D7=95=D7=AA?= =?UTF-8?q?=D7=A8=D7=AA=20=D7=94=D7=9B=D7=A8=D7=98=D7=99=D7=A1=D7=99=D7=99?= =?UTF-8?q?=D7=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/pdf_commentators_tab_screen.dart | 70 ++++++++++--------- .../view/commentators_tab_screen.dart | 16 ++++- .../pdf_commentators_tab_screen_test.dart | 16 +++-- .../view/commentators_tab_position_test.dart | 7 ++ 4 files changed, 70 insertions(+), 39 deletions(-) diff --git a/lib/pdf_book/view/pdf_commentators_tab_screen.dart b/lib/pdf_book/view/pdf_commentators_tab_screen.dart index 2ea688f6d1..fa55700727 100644 --- a/lib/pdf_book/view/pdf_commentators_tab_screen.dart +++ b/lib/pdf_book/view/pdf_commentators_tab_screen.dart @@ -23,6 +23,7 @@ import 'package:otzaria/book_common/utils/commentary_search_utils.dart'; import 'package:otzaria/book_common/utils/commentary_type_filter.dart'; import 'package:otzaria/models/books.dart'; import 'package:otzaria/data/repository/data_repository.dart'; +import 'package:otzaria/utils/text/ref_helper.dart'; import 'package:otzaria/utils/text/text_manipulation.dart' as utils; import 'package:otzaria/utils/navigation/open_book.dart'; import 'package:otzaria/utils/file/page_converter.dart'; @@ -113,8 +114,9 @@ class _PdfCommentatorsTabScreenState extends State final headings = _sortedHeadings; if (headings == null || idx < 0 || idx >= headings.length) return; final source = widget.tab.sourceTab; - source.currentTitle.value = headings[idx].key; - _pdfPageForHeading(idx).then((page) { + final heading = headings[idx]; + source.currentTitle.value = heading.key; + _pdfPageForHeading(source.book, heading.value).then((page) { if (page != null && mounted && version == _headingSelectionVersion) { source.pageNumber = page; } @@ -907,10 +909,15 @@ class _PdfCommentatorsTabScreenState extends State }); } - /// עמוד ה-PDF של הכותרת [idx]; null כשאין מיפוי אמין. - Future _pdfPageForHeading(int idx) async { - final book = widget.tab.sourceTab.book; - final line = _sortedHeadings![idx].value; + MapEntry? get _selectedHeading { + final headings = _sortedHeadings; + final index = _selectedHeadingIdx; + if (headings == null || index < 0 || index >= headings.length) return null; + return headings[index]; + } + + /// עמוד ה-PDF של שורת הכותרת, אם נמצא לה מיפוי. + Future _pdfPageForHeading(PdfBook book, int line) async { try { final library = await DataRepository.instance.library; final textBook = library.getCompanionBook(book, TextBook) as TextBook?; @@ -923,38 +930,27 @@ class _PdfCommentatorsTabScreenState extends State } Future _addBookmark(BuildContext context) async { - final sourceTab = widget.tab.sourceTab; + final source = widget.tab.sourceTab; final bookmarkBloc = context.read(); - final headings = _sortedHeadings; - final hasSelectedHeading = - headings != null && - _selectedHeadingIdx >= 0 && - _selectedHeadingIdx < headings.length; - - // הכותרת הנבחרת בכרטיסייה (כפי שמוצג בסרגל), ולא מצב הספר המקורי - final heading = hasSelectedHeading - ? headings[_selectedHeadingIdx].key.trim() - : sourceTab.currentTitle.value.trim(); - - // עמוד ברירת מחדל — מצב הספר המקורי אם אין כותרת נבחרת - int page = sourceTab.pdfViewerController.isReady - ? (sourceTab.pdfViewerController.pageNumber ?? sourceTab.pageNumber) - : sourceTab.pageNumber; - - // המרת שורת הכותרת הנבחרת לעמוד PDF מדויק; אם לא ניתן — נשארים על ברירת המחדל - if (hasSelectedHeading) { - page = await _pdfPageForHeading(_selectedHeadingIdx) ?? page; + final book = source.book; + final selected = _selectedHeading; + final heading = (selected?.key ?? source.currentTitle.value).trim(); + final commentators = source.activeCommentators.toList(); + int page = source.pdfViewerController.isReady + ? (source.pdfViewerController.pageNumber ?? source.pageNumber) + : source.pageNumber; + if (selected != null) { + page = await _pdfPageForHeading(book, selected.value) ?? page; } - - final ref = heading.isNotEmpty - ? '${sourceTab.book.title} $heading' - : '${sourceTab.book.title} עמוד $page'; - + final ref = addBookTitleToRef( + heading.isEmpty ? 'עמוד $page' : heading, + book.title, + ); final added = bookmarkBloc.addPdfCommentatorsBookmark( ref: 'מפרשים | $ref', - book: sourceTab.book, + book: book, index: page, - commentatorsToShow: sourceTab.activeCommentators.toList(), + commentatorsToShow: commentators, pdfCommentatorsHeading: heading.isEmpty ? null : heading, ); UiSnack.show( @@ -964,8 +960,14 @@ class _PdfCommentatorsTabScreenState extends State Widget _buildAppTopBar(BuildContext context) { final isCompact = AppDensity.of(context).isCompact; + final source = widget.tab.sourceTab; + final heading = (_selectedHeading?.key ?? source.currentTitle.value).trim(); + final ref = addBookTitleToRef( + heading.isEmpty ? 'עמוד ${source.pageNumber}' : heading, + source.book.title, + ); return CommentatorsTabTopBar( - title: 'מפרשים על ${widget.tab.sourceTab.book.title}', + title: 'מפרשים על $ref', titleMaxLines: 1, prevMajorTooltip: 'הכותרת הקודמת', nextMajorTooltip: 'הכותרת הבאה', diff --git a/lib/text_book/view/commentators_tab_screen.dart b/lib/text_book/view/commentators_tab_screen.dart index 2792de91a9..09fbce5465 100644 --- a/lib/text_book/view/commentators_tab_screen.dart +++ b/lib/text_book/view/commentators_tab_screen.dart @@ -1083,6 +1083,20 @@ class _CommentatorsTabScreenState extends State // ── AppBar ───────────────────────────────────────────────────────────────── + String _currentTitleRef(TextBookLoaded state, List chapters) { + final chapter = _selectedChapter; + final String ref; + if (chapter != null && chapters.contains(chapter)) { + final child = _selectedVerseIdx >= 0 + ? chapter.children.elementAtOrNull(_selectedVerseIdx) + : null; + ref = (child ?? chapter).fullText; + } else { + ref = refFromTocList(widget.tab.currentIndex, state.tableOfContents); + } + return addBookTitleToRef(refUpToDaf(ref), state.book.title); + } + Widget _buildAppBar( BuildContext context, TextBookLoaded state, @@ -1100,7 +1114,7 @@ class _CommentatorsTabScreenState extends State ), ); return CommentatorsTabTopBar( - title: 'מפרשים על ${state.book.title}', + title: 'מפרשים על ${_currentTitleRef(state, chapters)}', prevMajorTooltip: 'הפרק הקודם', nextMajorTooltip: 'הפרק הבא', navPaneOpen: _navPaneOpen, diff --git a/test/pdf_book/pdf_commentators_tab_screen_test.dart b/test/pdf_book/pdf_commentators_tab_screen_test.dart index c16d71cb8d..56bdcf328a 100644 --- a/test/pdf_book/pdf_commentators_tab_screen_test.dart +++ b/test/pdf_book/pdf_commentators_tab_screen_test.dart @@ -133,20 +133,28 @@ void main() { addTearDown(sourceTab.dispose); sourceTab.pdfHeadings = PdfHeadings( bookTitle: 'PDF בדיקה', - headingsMap: {'פרק א': 1, 'פרק ב': 10}, + headingsMap: {'PDF בדיקה': 1, 'פרק ב': 10}, ); - sourceTab.currentTitle.value = 'פרק א'; + sourceTab.currentTitle.value = 'PDF בדיקה'; final tab = PdfCommentatorsTab(sourceTab: sourceTab); await tester.pumpWidget(_wrap(PdfCommentatorsTabScreen(tab: tab))); await tester.pump(); - expect(find.text('מפרשים על PDF בדיקה פרק א'), findsOneWidget); + expect(find.text('מפרשים על PDF בדיקה'), findsOneWidget); sourceTab.currentTitle.value = 'פרק ב'; await tester.pump(); - expect(find.text('מפרשים על PDF בדיקה פרק ב'), findsOneWidget); + expect(find.text('מפרשים על PDF בדיקה, פרק ב'), findsOneWidget); + await tester.pumpWidget(const SizedBox.shrink()); + sourceTab.pdfHeadings = null; + sourceTab.currentTitle.value = ''; + sourceTab.pageNumber = 7; + await tester.pumpWidget(_wrap(PdfCommentatorsTabScreen(tab: tab))); + await tester.pump(); + + expect(find.text('מפרשים על PDF בדיקה, עמוד 7'), findsOneWidget); }); testWidgets('כרטסיית מפרשי PDF מסתנכרנת עם currentTitle של sourceTab', ( diff --git a/test/text_book/view/commentators_tab_position_test.dart b/test/text_book/view/commentators_tab_position_test.dart index cba61f76ee..2efe858b09 100644 --- a/test/text_book/view/commentators_tab_position_test.dart +++ b/test/text_book/view/commentators_tab_position_test.dart @@ -24,6 +24,8 @@ class _LoadingTextBookBloc extends Bloc }); } + void replaceLoaded(TextBookLoaded loaded) => emit(loaded); + @override dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); } @@ -163,5 +165,10 @@ void main() { await tester.pump(); expect(find.text('מפרשים על כתובות, דף ב'), findsOneWidget); + + tabBloc.replaceLoaded(_loaded(book, [TocEntry(text: 'דף ג', index: 0)], 0)); + await tester.pump(); + + expect(find.text('מפרשים על כתובות, דף ג'), findsOneWidget); }); }