Skip to content

Commit d12849c

Browse files
Merge pull request #5963 from dudua99/fix/5290-multiline-copy
שמירת קישורים בהעתקה מעוצבת החוצה שורות מקור
2 parents dca1164 + 4639022 commit d12849c

12 files changed

Lines changed: 909 additions & 302 deletions

File tree

‎lib/plugins/models/plugin_network_allowlist.g.dart‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/text_book/view/combined_view/combined_book_screen.dart‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,14 +1814,19 @@ class _CombinedViewState extends State<CombinedView> {
18141814
final textBookState = context.read<TextBookBloc>().state;
18151815
if (textBookState is! TextBookLoaded) return;
18161816

1817+
final selectedIndex = _currentSelectedIndex.value;
1818+
final lineStart = _selectionLineStart;
1819+
final lineEnd = _selectionLineEnd;
18171820
await copySelectedTextForBook(
18181821
plainText: plainText,
1819-
selectedIndex: _currentSelectedIndex.value,
1822+
selectedIndex: selectedIndex,
1823+
selectionLineStart: lineStart,
1824+
selectionLineEnd: lineEnd,
18201825
sourceContent: widget.data,
18211826
textBookState: textBookState,
18221827
segmentCount: selectionSegmentCount(
1823-
start: _selectionLineStart,
1824-
end: _selectionLineEnd,
1828+
start: lineStart,
1829+
end: lineEnd,
18251830
text: plainText,
18261831
),
18271832
settingsState: settingsState,
@@ -1849,17 +1854,21 @@ class _CombinedViewState extends State<CombinedView> {
18491854
final sourceWidget = widget;
18501855
final settingsState = context.read<SettingsBloc>().state;
18511856
final selectedIndex = _currentSelectedIndex.value;
1857+
final lineStart = _selectionLineStart;
1858+
final lineEnd = _selectionLineEnd;
18521859
final source = _sourceSelection;
18531860
final segmentCount = selectionSegmentCount(
1854-
start: _selectionLineStart,
1855-
end: _selectionLineEnd,
1861+
start: lineStart,
1862+
end: lineEnd,
18561863
text: capturedText,
18571864
);
18581865
return () async {
18591866
if (!ensureCopyAllowed(state.protection, segmentCount)) return null;
18601867
final content = await buildSelectedTextCopy(
18611868
plainText: capturedText,
18621869
selectedIndex: selectedIndex,
1870+
selectionLineStart: lineStart,
1871+
selectionLineEnd: lineEnd,
18631872
sourceContent: sourceWidget.data,
18641873
textBookState: state,
18651874
settingsState: settingsState,

‎lib/text_book/view/page_shape/simple_text_viewer.dart‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,35 +2860,44 @@ class _SimpleTextViewerState extends State<SimpleTextViewer> {
28602860
try {
28612861
final textBookState = context.read<TextBookBloc>().state;
28622862
if (textBookState is! TextBookLoaded) return;
2863+
final selectedIndex = _savedSelectedIndex;
2864+
final lineStart = _selectionLineStart;
2865+
final lineEnd = _selectionLineEnd;
2866+
final sourceWidget = widget;
2867+
final source = _sourceSelection;
2868+
final headerIndex = _sourceIndex(selectedIndex);
2869+
final copyTarget = _textTarget;
28632870
final protection = await _textProtection(textBookState);
28642871
if (!mounted) return;
28652872
final settingsState = context.read<SettingsBloc>().state;
28662873

28672874
await copySelectedTextForBook(
28682875
plainText: plainText,
2869-
selectedIndex: _savedSelectedIndex,
2870-
sourceContent: widget.content,
2876+
selectedIndex: selectedIndex,
2877+
selectionLineStart: lineStart,
2878+
selectionLineEnd: lineEnd,
2879+
sourceContent: sourceWidget.content,
28712880
textBookState: textBookState,
28722881
protection: protection,
28732882
segmentCount: selectionSegmentCount(
2874-
start: _selectionLineStart,
2875-
end: _selectionLineEnd,
2883+
start: lineStart,
2884+
end: lineEnd,
28762885
text: plainText,
28772886
),
28782887
settingsState: settingsState,
2879-
fontFamily: widget.fontFamily ?? settingsState.fontFamily,
2880-
fontSize: widget.fontSize,
2881-
headerBookOverride: widget.reportBook,
2882-
headerIndexOverride: _sourceIndex(_savedSelectedIndex),
2883-
headerContentOverride: widget.isBookNotesColumn
2888+
fontFamily: sourceWidget.fontFamily ?? settingsState.fontFamily,
2889+
fontSize: sourceWidget.fontSize,
2890+
headerBookOverride: sourceWidget.reportBook,
2891+
headerIndexOverride: headerIndex,
2892+
headerContentOverride: sourceWidget.isBookNotesColumn
28842893
? textBookState.content
2885-
: widget.reportBook != null
2886-
? widget.content
2894+
: sourceWidget.reportBook != null
2895+
? sourceWidget.content
28872896
: null,
28882897
removeNikud: removeNikud,
28892898
copyProfile: profile,
2890-
copyTarget: _textTarget,
2891-
source: _sourceSelection,
2899+
copyTarget: copyTarget,
2900+
source: source,
28922901
plainTextOnly: plainTextOnly,
28932902
);
28942903
} catch (e) {
@@ -2908,12 +2917,14 @@ class _SimpleTextViewerState extends State<SimpleTextViewer> {
29082917
final sourceWidget = widget;
29092918
final settings = context.read<SettingsBloc>().state;
29102919
final selectedIndex = _savedSelectedIndex;
2920+
final lineStart = _selectionLineStart;
2921+
final lineEnd = _selectionLineEnd;
29112922
final source = _sourceSelection;
29122923
final copyTarget = _textTarget;
29132924
final headerIndex = _sourceIndex(selectedIndex);
29142925
final segmentCount = selectionSegmentCount(
2915-
start: _selectionLineStart,
2916-
end: _selectionLineEnd,
2926+
start: lineStart,
2927+
end: lineEnd,
29172928
text: capturedText,
29182929
);
29192930
return () async {
@@ -2925,6 +2936,8 @@ class _SimpleTextViewerState extends State<SimpleTextViewer> {
29252936
final content = await buildSelectedTextCopy(
29262937
plainText: capturedText,
29272938
selectedIndex: selectedIndex,
2939+
selectionLineStart: lineStart,
2940+
selectionLineEnd: lineEnd,
29282941
sourceContent: sourceWidget.content,
29292942
textBookState: state,
29302943
settingsState: settings,

‎lib/text_book/view/selection/selected_text_copy.dart‎

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/// שהשורה תושווה לבחירה כפי שהיא על המסך.
2022
String 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

Comments
 (0)