diff --git a/lib/text_book/view/selection/selected_text_copy.dart b/lib/text_book/view/selection/selected_text_copy.dart index c658dd007b..a09f4d8b95 100644 --- a/lib/text_book/view/selection/selected_text_copy.dart +++ b/lib/text_book/view/selection/selected_text_copy.dart @@ -201,14 +201,26 @@ Future<({String plainText, String htmlText})?> buildSelectedTextCopy({ selectionLineEnd: selectionLineEnd, divineNames: showsSubstitutedNames ? textBookState.divineNames : null, ); + ({String plainText, String htmlText}) applyPreferences( + String plain, + String html, + ) => CopyUtils.applyCopyPreferencesForClipboard( + plainText: plain, + htmlText: html, + replaceHolyNames: settingsState.replaceHolyNames, + holyNameStyle: settingsState.holyNameStyle, + removeNikud: removeNikud, + profile: profile, + ); var finalPlainText = plainText; final headerBook = headerBookOverride ?? textBookState?.book; + var processedSeparately = false; if (settingsState.copyWithHeaders != 'none' && headerBook != null) { - final bookName = CopyUtils.extractBookName(headerBook); + var bookName = CopyUtils.extractBookName(headerBook); final currentIndex = headerIndexOverride ?? selectedIndex ?? 0; final headerContent = headerContentOverride ?? sourceContent; - final currentPath = await CopyUtils.extractCurrentPath( + var currentPath = await CopyUtils.extractCurrentPath( headerBook, currentIndex, bookContent: headerContent, @@ -219,6 +231,19 @@ Future<({String plainText, String htmlText})?> buildSelectedTextCopy({ : null, ); + // מסננים לפני הצירוף כדי שהסרת פיסוק לא תחבר את הכותרת לגוף. + final format = settingsState.copyHeaderFormat; + if (profile != null && + profile.removePunctuation && + (format == 'separate_line_before' || format == 'separate_line_after')) { + final copy = applyPreferences(plainText, htmlContentToUse); + plainText = copy.plainText; + htmlContentToUse = copy.htmlText; + bookName = applyTextDisplayProfile(bookName, profile); + currentPath = applyTextDisplayProfile(currentPath, profile); + processedSeparately = true; + } + finalPlainText = CopyUtils.formatTextWithHeaders( originalText: plainText, copyWithHeaders: settingsState.copyWithHeaders, @@ -236,12 +261,7 @@ Future<({String plainText, String htmlText})?> buildSelectedTextCopy({ ); } - return CopyUtils.applyCopyPreferencesForClipboard( - plainText: finalPlainText, - htmlText: htmlContentToUse, - replaceHolyNames: settingsState.replaceHolyNames, - holyNameStyle: settingsState.holyNameStyle, - removeNikud: removeNikud, - profile: profile, - ); + return processedSeparately + ? (plainText: finalPlainText, htmlText: htmlContentToUse) + : applyPreferences(finalPlainText, htmlContentToUse); } diff --git a/test/text_book/view/selection/selected_text_copy_test.dart b/test/text_book/view/selection/selected_text_copy_test.dart index 7a07e1b6f5..56b00e9005 100644 --- a/test/text_book/view/selection/selected_text_copy_test.dart +++ b/test/text_book/view/selection/selected_text_copy_test.dart @@ -481,6 +481,96 @@ void main() { ); expect(copied, isNull); }); + + group('כותרת בשורה נפרדת כשערוץ ההעתקה מסתיר פיסוק (#5463)', () { + // פסוק כפי שהוא בספר בראשית; הכותרת "פרק א" אינה מסתיימת בנקודה. + const verse = + '(א) בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃'; + const plainVerse = + '(א) בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃'; + const header = 'ספר בדיקה, פרק א'; + + Future<({String plainText, String htmlText})> copyVerse( + String format, { + String heading = 'פרק א', + bool removeNikud = false, + }) async { + final state = _state( + verse, + link, + const TextDisplayPatch(punctuation: MarkVisibility.hide), + ).copyWith(content: ['