@@ -15,27 +15,53 @@ import 'package:otzaria/utils/text/html_slice.dart';
1515/// בוחר את תוכן ה-HTML המתאים ביותר לטקסט שנבחר: השורה המקורית כשהיא
1616/// נבחרה במלואה, אחרת חיתוך שלה לטווח הבחירה — כדי שגם בחירה חלקית
1717/// תישמר מעוצבת. נופל לטקסט פשוט רק כשהבחירה אינה נמצאת בשורה.
18+ /// [selectionLineStart] ו־[selectionLineEnd] הם גבולות המקור שזוהו בקורא,
19+ /// כולל שורות הקצה. בהיעדרם החיתוך מוגבל לשורה [selectedIndex] .
1820/// [divineNames] — מופעי השמות של [sourceContent] כשהם מוצגים מוחלפים, כדי
1921/// שהשורה תושווה לבחירה כפי שהיא על המסך.
2022String resolveHtmlTextForSelection ({
2123 required String plainText,
2224 required int ? selectedIndex,
2325 required List <String > sourceContent,
26+ int ? selectionLineStart,
27+ int ? selectionLineEnd,
2428 DivineNameSpans ? divineNames,
2529}) {
30+ String sourceLine (int index) {
31+ final line = sourceContent[index];
32+ if (divineNames == null || divineNames.isEmpty) return line;
33+ return resolveDivineNameMarkers (
34+ injectDivineNameMarkers (line, divineNames, index),
35+ substituteOtherNames: true ,
36+ );
37+ }
38+
39+ if (selectionLineStart != null || selectionLineEnd != null ) {
40+ if (selectionLineStart == null ||
41+ selectionLineEnd == null ||
42+ selectionLineStart < 0 ||
43+ selectionLineEnd < selectionLineStart ||
44+ selectionLineEnd >= sourceContent.length) {
45+ return plainText;
46+ }
47+ if (selectionLineStart < selectionLineEnd) {
48+ return sliceHtmlLinesBySelection (
49+ lines: [
50+ for (var i = selectionLineStart; i <= selectionLineEnd; i++ )
51+ sourceLine (i),
52+ ],
53+ selectedText: plainText,
54+ ) ??
55+ plainText;
56+ }
57+ selectedIndex = selectionLineStart;
58+ }
2659 if (selectedIndex == null ||
2760 selectedIndex < 0 ||
2861 selectedIndex >= sourceContent.length) {
2962 return plainText;
3063 }
31-
32- var originalData = sourceContent[selectedIndex];
33- if (divineNames != null && ! divineNames.isEmpty) {
34- originalData = resolveDivineNameMarkers (
35- injectDivineNameMarkers (originalData, divineNames, selectedIndex),
36- substituteOtherNames: true ,
37- );
38- }
64+ final originalData = sourceLine (selectedIndex);
3965 final plainTextCleaned = plainText.replaceAll (RegExp (r'\s+' ), ' ' ).trim ();
4066 final originalCleaned = originalData
4167 .replaceAll (RegExp (r'<[^>]*>' ), '' )
@@ -54,7 +80,7 @@ String resolveHtmlTextForSelection({
5480}
5581
5682/// מעתיק טקסט נבחר מספר טקסט תוך שמירה על כותרות ועיצוב.
57- /// [headerIndexOverride] ממפה מראה מקום בלבד; ה־HTML נחתך לפי [selectedIndex] .
83+ /// [headerIndexOverride] ממפה מראה מקום בלבד; ה־HTML נחתך לפי טווח המקור .
5884///
5985/// [textBookState] הוא null בהעתקה ממשטח ללא `TextBookBloc` (חלונית ה-PDF);
6086/// אז [headerBookOverride] הוא מקור ספר הכותרת היחיד.
@@ -70,6 +96,8 @@ Future<void> copySelectedTextForBook({
7096 required String plainText,
7197 required int ? selectedIndex,
7298 required List <String > sourceContent,
99+ int ? selectionLineStart,
100+ int ? selectionLineEnd,
73101 required TextBookLoaded ? textBookState,
74102 required SettingsState settingsState,
75103 required String fontFamily,
@@ -95,6 +123,8 @@ Future<void> copySelectedTextForBook({
95123 plainText: plainText,
96124 selectedIndex: selectedIndex,
97125 sourceContent: sourceContent,
126+ selectionLineStart: selectionLineStart,
127+ selectionLineEnd: selectionLineEnd,
98128 textBookState: textBookState,
99129 settingsState: settingsState,
100130 headerBookOverride: headerBookOverride,
@@ -129,6 +159,8 @@ Future<({String plainText, String htmlText})?> buildSelectedTextCopy({
129159 required String plainText,
130160 required int ? selectedIndex,
131161 required List <String > sourceContent,
162+ int ? selectionLineStart,
163+ int ? selectionLineEnd,
132164 required TextBookLoaded ? textBookState,
133165 required SettingsState settingsState,
134166 TextBook ? headerBookOverride,
@@ -165,6 +197,8 @@ Future<({String plainText, String htmlText})?> buildSelectedTextCopy({
165197 plainText: plainText,
166198 selectedIndex: selectedIndex,
167199 sourceContent: sourceContent,
200+ selectionLineStart: selectionLineStart,
201+ selectionLineEnd: selectionLineEnd,
168202 divineNames: showsSubstitutedNames ? textBookState.divineNames : null ,
169203 );
170204
0 commit comments