Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions lib/text_book/view/page_shape/page_shape_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,7 @@ class _CommentaryPaneState extends State<_CommentaryPane> {

if (attachedRecord != null) {
book = TextBook(
id: attachedRecord.book.id,
title: widget.commentatorName,
categoryId: attachedRecord.book.categoryId,
source: attachedRecord.source,
Expand All @@ -2702,7 +2703,11 @@ class _CommentaryPaneState extends State<_CommentaryPane> {
bookLocation.book != null &&
bookLocation.categoryId != null) {
// נמצא ספר ב-DB - נשתמש בנתונים שלו
// המזהה מאפשר את אייקון "קישור" בתפריט ההקשר של המפרש. רק לספר
// רשמי: ה-TextBook כאן נשאר במקור הרשמי, ומזהה של ספר אישי היה
// מפנה לספר רשמי אחר בעל אותו מזהה.
book = TextBook(
id: bookLocation.source.isOfficial ? bookLocation.book!.id : null,
title: widget.commentatorName,
categoryId: bookLocation.categoryId,
);
Expand Down
58 changes: 33 additions & 25 deletions lib/text_book/view/page_shape/simple_text_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2080,14 +2080,42 @@ class _SimpleTextViewerState extends State<SimpleTextViewer> {
lineStart: _selectionLineStart,
lineEnd: _selectionLineEnd,
);
// אותה שורת אייקונים ואותו סדר כמו במפרשים בתצוגה הרגילה
// (ContextMenuUtils.buildCommentaryContextMenu): חיפוש, העתקה, הערה, קישור.
// הקישור לפי book_id של המפרש בלבד; categoryId היה פותח ספר אחר.
final commentaryBookId = widget.reportBook?.id;
entries.add(
AppContextMenuEntry.iconRow([
buildSearchAllBooksIconAction(
selection: menuSelection,
onTap: () => openGlobalSearch(menuContext, menuSelection.cleaned),
),
AppContextMenuIconAction(
label: 'העתקה',
icon: FluentIcons.copy_24_regular,
enabled: capturedText != null && capturedText.trim().isNotEmpty,
onTap: () => _copyFormattedText(capturedText),
),
AppContextMenuIconAction(
label: 'הערה',
icon: FluentIcons.note_add_24_regular,
onTap: () => _createNoteForCurrentLine(index, capturedText),
),
if (commentaryBookId != null)
AppContextMenuIconAction(
label: 'קישור',
icon: OtzariaIcons.link_24_regular,
submenuBuilder: () => buildDirectLinkSubmenuActions(
bookId: commentaryBookId,
source: widget.reportBook?.source ?? BookSource.official,
index: index,
selectedText: sourceText,
protection: () => _textProtection(state),
),
),
]),
);
entries.add(_copyAsEntry(state, capturedText));
}

if (commentatorItems.isNotEmpty) {
Expand Down Expand Up @@ -2156,22 +2184,16 @@ class _SimpleTextViewerState extends State<SimpleTextViewer> {
icon: FluentIcons.bookmark_add_24_regular,
onTap: () => addTextSectionBookmark(context, state, index),
),
// בטקסט ראשי "הוסף הערה" ו"העתק" קיימים כאייקונים למעלה; במפרשים
// (ללא שורת אייקונים) הם נשארים כאן ברשימה.
if (!widget.isMainText && !widget.isBookNotesColumn)
AppContextMenuEntry(
label: 'הוסף הערה אישית ',
icon: FluentIcons.note_add_24_regular,
onTap: () => _createNoteForCurrentLine(index, capturedText),
),
// "הוסף הערה" ו"העתק" מוצגים כאייקונים בשורה העליונה (בטקסט הראשי
// ובמפרשים); רק בעמודת ההערות, שאין בה שורת אייקונים, "העתק" נשאר כאן.
if (reportTargetBook.isOfficialLibraryBook)
AppContextMenuEntry(
label: 'דווח על טעות בספר',
icon: FluentIcons.error_circle_24_regular,
onTap: () => _openErrorReportDialog(capturedText ?? ''),
),
const AppContextMenuEntry.divider(),
if (!widget.isMainText) ...[
if (widget.isBookNotesColumn) ...[
AppContextMenuEntry(
label: 'העתק',
icon: FluentIcons.copy_24_regular,
Expand All @@ -2188,8 +2210,7 @@ class _SimpleTextViewerState extends State<SimpleTextViewer> {
),
]);

// העתק קישור ישיר — בטקסט ראשי מוצג כאייקון בשורה העליונה; במפרשים
// (ללא שורת אייקונים) נשאר כתת-תפריט ברשימה לפי book_id של widget.reportBook.
// העתק קישור ישיר מוצג כאייקון "קישור" בשורה העליונה, בטקסט הראשי ובמפרשים.
if (widget.isMainText) {
entries.addAll(
buildReaderPluginMenuEntries(
Expand Down Expand Up @@ -2223,20 +2244,7 @@ class _SimpleTextViewerState extends State<SimpleTextViewer> {
),
);
} else {
// רק book_id של המפרש; categoryId אינו תחליף — הוא היה פותח ספר אחר.
final commentaryBookId = widget.reportBook?.id;
if (commentaryBookId != null) {
entries.add(const AppContextMenuEntry.divider());
entries.add(
buildCopyDirectLinkEntry(
bookId: commentaryBookId,
source: widget.reportBook?.source ?? BookSource.official,
index: index,
selectedText: capturedText,
protection: () => _textProtection(state),
),
);
}
// העתק קישור ישיר במפרשים מוצג כאייקון "קישור" בשורה העליונה.
entries.addAll(
_commentaryPluginEntries(state, index, sourceText, menuContext),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ void main() {
await openContextMenu(tester);
expect(find.text('מפרשים על פסקה זו'), findsNothing);
expect(find.text('קישורים'), findsNothing);
expect(find.textContaining('הוסף הערה אישית'), findsOneWidget);
expect(find.text('הערה'), findsOneWidget);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:otzaria/settings/engine/app_settings_store.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:otzaria/book_common/models/commentator_group.dart';
import 'package:otzaria/book_protection/repository/book_protection_repository.dart';
import 'package:otzaria/models/book_source.dart';
import 'package:otzaria/models/books.dart';
import 'package:otzaria/models/links.dart';
import 'package:otzaria/personal_notes/bloc/personal_notes_bloc.dart';
Expand Down Expand Up @@ -41,6 +45,10 @@ void main() {
TextBook? book,
List<String> availableCommentators = const [],
bool isMainText = true,
TextBook? reportBook,
List<String> content = const ['שורה א'],
Map<int, List<Link>> anchorLinksByLine = const {},
int? selectLine,
PluginMenuClickRecorder? recorder,
void Function(List<AppContextMenuEntry> entries)? onMenu,
}) async {
Expand Down Expand Up @@ -71,11 +79,13 @@ void main() {
child: (recorder?.wrap ?? (Widget child) => child)(
Scaffold(
body: SimpleTextViewer(
content: const ['שורה א'],
content: content,
fontSize: 18,
openBookCallback: (_) {},
isMainText: isMainText,
bookTitle: isMainText ? null : 'רש"י על ספר בדיקה',
reportBook: reportBook,
anchorLinksByLine: anchorLinksByLine,
onOpenCommentatorsPane: () {},
onOpenCommentatorsPaneWithFilter: () {},
),
Expand All @@ -86,7 +96,20 @@ void main() {
);
await tester.pumpAndSettle();

final regionFinder = find.byType(AppContextMenuRegion).first;
final regionFinder = find.byType(AppContextMenuRegion).at(selectLine ?? 0);
if (selectLine != null) {
final renderedText = tester.allRenderObjects
.whereType<RenderParagraph>()
.map((paragraph) => paragraph.text.toPlainText())
.singleWhere(
(text) => text.contains(content[selectLine].split(' ').first),
);
expect(renderedText, contains('(ז)'));
tester
.widget<SelectableRegion>(find.byType(SelectableRegion))
.onSelectionChanged!(SelectedContent(plainText: renderedText));
await tester.pump();
}
List<String> build() {
final region = tester.widget<AppContextMenuRegion>(regionFinder);
final entries = region.menuBuilder(
Expand Down Expand Up @@ -170,12 +193,8 @@ void main() {

testWidgets('a commentary column', (tester) async {
expect(await menuFor(tester, isMainText: false), [
'[חיפוש (disabled)]',
'---',
'הוסף הערה אישית ',
'דווח על טעות בספר',
'---',
'העתק (disabled)',
// Same icon row, in the same order, as the combined view's commentary.
'[חיפוש (disabled) | העתקה (disabled) | הערה]',
'העתק כ... (disabled)',
' ניקוד (disabled) [x]',
' טעמים (disabled) [x]',
Expand All @@ -185,10 +204,100 @@ void main() {
' ---',
' העתק (disabled)',
' כמו בתצוגה (disabled)',
'---',
'דווח על טעות בספר',
'---',
'העתק את כל הפסקה',
]);
});

testWidgets('a commentary column with a book id offers the link icon', (
tester,
) async {
final menu = await menuFor(
tester,
isMainText: false,
reportBook: TextBook(title: 'רש"י על ספר בדיקה', id: 9),
);
expect(
menu.first,
'[חיפוש (disabled) | העתקה (disabled) | הערה | קישור >]',
);
expect(menu, isNot(contains('העתק קישור ישיר')));
});

for (final source in [BookSource.official, BookSource.attached('test-db')]) {
testWidgets(
'commentary link highlights source text from ${source.wireKey}',
(
tester,
) async {
const sourceText = 'בראשית ברא העולם';
final checkedSources = <BookSource>[];
BookProtectionRepository.instance.debugRepositoryFor = (source) async {
checkedSources.add(source);
return null;
};
addTearDown(BookProtectionRepository.instance.debugReset);

late List<AppContextMenuEntry> entries;
await menuFor(
tester,
isMainText: false,
reportBook: TextBook(title: 'פירוש בדיקה', id: 9, source: source),
content: const ['שורה קודמת', sourceText],
anchorLinksByLine: {
2: [
Link(
heRef: 'שער הציון, ז',
index1: 2,
index2: 1,
path2: 'שער הציון',
connectionType: 'commentary',
anchorStart: 7,
anchorLabel: 'ז',
),
],
},
selectLine: 1,
onMenu: (menu) => entries = menu,
);
String? clipboard;
final messenger =
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
messenger.setMockMethodCallHandler(SystemChannels.platform, (
call,
) async {
if (call.method == 'Clipboard.setData') {
clipboard = (call.arguments as Map)['text'] as String?;
}
return null;
});
addTearDown(
() =>
messenger.setMockMethodCallHandler(SystemChannels.platform, null),
);

entries.first.iconRowActions!
.singleWhere((action) => action.label == 'קישור')
.submenuBuilder!()
.singleWhere((action) => action.label.contains('הדגשת הטקסט'))
.onTap!();
await tester.pumpAndSettle();

final link = Uri.parse(clipboard!);
expect(link.path, '/book/9');
expect(link.queryParameters['index'], '1');
expect(
link.queryParameters['source'],
source.isAttached ? 'db:test-db' : null,
);
expect(link.queryParameters['m'], sourceText);
expect(checkedSources, [source]);
},
);
}

testWidgets('a commentary column gives reader-commentary items its line', (
tester,
) async {
Expand Down
9 changes: 5 additions & 4 deletions test/text_book/view/page_shape/simple_text_viewer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1403,11 +1403,11 @@ void main() {
await gesture.up();
await tester.pumpAndSettle();

final addNoteFinder = find.textContaining('הוסף הערה אישית');
final addNoteFinder = find.text('הערה');
expect(
addNoteFinder,
findsOneWidget,
reason: 'תפריט ההקשר במפרש חייב לכלול "הוסף הערה אישית"',
reason: 'תפריט ההקשר במפרש חייב לכלול את אייקון "הערה"',
);

await tester.tap(addNoteFinder);
Expand Down Expand Up @@ -1495,7 +1495,7 @@ void main() {
await gesture.up();
await tester.pumpAndSettle();

await tester.tap(find.textContaining('הוסף הערה אישית'));
await tester.tap(find.text('הערה'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));

Expand Down Expand Up @@ -1573,7 +1573,8 @@ void main() {
tester.getCenter(find.byType(AppContextMenuRegion).first),
);
entries
.singleWhere((entry) => entry.label?.trim() == 'הוסף הערה אישית')
.expand((entry) => entry.iconRowActions ?? const [])
.singleWhere((action) => action.label == 'הערה')
.onTap!();
await tester.pumpAndSettle();
expect(outerCalls, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,10 @@ void main() {
);
}

var search = entries().first.iconRowActions!.single;
expect(search.label, 'חיפוש');
final icons = entries().first.iconRowActions!;
// Same order as the combined view's commentary row.
expect(icons.map((a) => a.label), ['חיפוש', 'העתקה', 'הערה']);
var search = icons.first;
expect(search.enabled, isFalse);

final regionFinder = find.descendant(
Expand All @@ -328,7 +330,7 @@ void main() {
);
await tester.pump();

search = entries().first.iconRowActions!.single;
search = entries().first.iconRowActions!.first;
expect(search.enabled, isTrue);
expect(search.tooltip, 'חיפוש "בראשית ברא" בכל הספרים');
search.onTap!();
Expand Down
Loading