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: ['

$heading

', verse]); + final copied = await buildSelectedTextCopy( + plainText: plainVerse, + selectedIndex: 1, + sourceContent: state.content, + textBookState: state, + settingsState: SettingsState.initial().copyWith( + copyWithHeaders: 'book_and_path', + copyHeaderFormat: format, + ), + copyTarget: TextTarget.body, + removeNikud: removeNikud, + ); + return copied!; + } + + test('כותרת לפני הטקסט', () async { + final copied = await copyVerse('separate_line_before'); + expect(copied.plainText, '$header\n$plainVerse'); + expect( + CopyUtils.buildStyledHtml( + htmlText: copied.htmlText, + fontFamily: 'Arial', + fontSize: 16, + ), + allOf( + startsWith('
$header
$verse'), + ), + ); + }); + + test('כותרת אחרי הטקסט', () async { + final copied = await copyVerse('separate_line_after'); + expect(copied.plainText, '$plainVerse\n$header'); + expect( + CopyUtils.buildStyledHtml( + htmlText: copied.htmlText, + fontFamily: 'Arial', + fontSize: 16, + ), + allOf(contains('>$verse'), endsWith('>$header')), + ); + }); + + test('העתק בלי ניקוד מסיר ניקוד וטעמים גם מכותרת נפרדת', () async { + final copied = await copyVerse( + 'separate_line_before', + heading: 'פֶּ֖רֶק א', + removeNikud: true, + ); + const unmarked = '(א) בראשית ברא אלהים את השמים ואת הארץ'; + const htmlUnmarked = + '(א) בראשית ברא אלהים את השמים ואת הארץ'; + expect(copied.plainText, '$header\n$unmarked'); + expect(copied.htmlText, '$header\n$htmlUnmarked'); + }); + + for (final entry in const { + 'same_line_after_brackets': '$plainVerse (ספר בדיקה פרק א)', + 'same_line_after_no_brackets': '$plainVerse ספר בדיקה פרק א', + 'same_line_before_brackets': '(ספר בדיקה פרק א) $plainVerse', + 'same_line_before_no_brackets': 'ספר בדיקה פרק א $plainVerse', + }.entries) { + test('סינון כותרת נשמר בתבנית ${entry.key}', () async { + final copied = await copyVerse(entry.key); + expect(copied.plainText, entry.value); + expect(copied.htmlText, entry.value.replaceFirst(plainVerse, verse)); + }); + } + }); }); }