sw/qa/extras/layout/data/tdf157596_paragraph_numbering.docx |binary
 sw/qa/extras/layout/layout2.cxx                             |   14 +++++++
 sw/source/core/text/txtfld.cxx                              |   24 ++++++------
 sw/source/core/txtnode/ndtxt.cxx                            |   11 +++++
 4 files changed, 38 insertions(+), 11 deletions(-)

New commits:
commit d4dc9a56d896b231e85448346f426615da138209
Author:     Bayram Çiçek <bayram.ci...@collabora.com>
AuthorDate: Tue Jun 17 10:38:59 2025 +0300
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Wed Jun 25 21:12:01 2025 +0200

    tdf#157596: add partly-deleted paragraphs to hidden list during fileopen
    
    - regression from commit 2413f213625253a9c2b1787b3b9fe859d724a9bd
    - if a paragraph is partly deleted, add it to the "hidden" list.
    - if we delete -at least- a single character from a paragraph (during 
Record Track Changes is enabled), Writer thinks the whole paragraph and the 
numbering is deleted. Therefore, the numbering of the paragraph does not get 
added to the hidden list.
    - this patch adds the partly-deleted paragraph numbering to the hidden list 
during fileopen.
    - added a unit test
    
    Signed-off-by: Bayram Çiçek <bayram.ci...@collabora.com>
    Change-Id: Ia8852eb7d61b57f15a037b2ffd3e6eec363f90af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186998
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/sw/qa/extras/layout/data/tdf157596_paragraph_numbering.docx 
b/sw/qa/extras/layout/data/tdf157596_paragraph_numbering.docx
new file mode 100644
index 000000000000..85395d89f447
Binary files /dev/null and 
b/sw/qa/extras/layout/data/tdf157596_paragraph_numbering.docx differ
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index 9803de21081a..d0a61c84195f 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -748,6 +748,20 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, 
testRedlineNumbering2)
     assertXPathContent(pXmlDoc, 
"/metafile/push/push/push/textarray[7]/text"_ostr, "4.[3.] ");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, tdf157596_paragraph_numbering)
+{
+    createSwDoc("tdf157596_paragraph_numbering.docx");
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+    // show correct numbering during fileload.
+    assertXPath(pXmlDoc, 
"/root/page/body/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
+                "expand"_ostr, "1.");
+    assertXPath(pXmlDoc, 
"/root/page/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
+                "expand"_ostr, "2.");
+    assertXPath(pXmlDoc, 
"/root/page/body/txt[3]/SwParaPortion/SwLineLayout/SwFieldPortion"_ostr,
+                "expand"_ostr, "3.");
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf149710_RedlineNumberingEditing)
 {
     createSwDoc("tdf149710.fodt");
diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index 84f32e30971f..e5ce080ee572 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -620,38 +620,40 @@ SwNumberPortion *SwTextFormatter::NewNumberPortion( 
SwTextFormatInfo &rInf ) con
                 // (SwListRedlineType::SHOW, which counts removed and inserted 
numbered paragraphs
                 // in a single list)
                 bool bHasHiddenNum = false;
-                OUString aText( pTextNd->GetNumString(true, MAXLEVEL, 
m_pFrame->getRootFrame(), SwListRedlineType::HIDDEN) );
+                OUString aTextNow( pTextNd->GetNumString(true, MAXLEVEL, 
m_pFrame->getRootFrame(), SwListRedlineType::HIDDEN) );
                 const SwDoc& rDoc = pTextNd->GetDoc();
                 const SwRedlineTable& rTable = 
rDoc.getIDocumentRedlineAccess().GetRedlineTable();
                 if ( rTable.size() && 
!rInf.GetVsh()->GetLayout()->IsHideRedlines() )
                 {
-                    OUString aHiddenText( pTextNd->GetNumString(true, 
MAXLEVEL, m_pFrame->getRootFrame(), SwListRedlineType::ORIGTEXT) );
+                    // previous (outdated) text
+                    OUString aOriginalText( pTextNd->GetNumString(true, 
MAXLEVEL, m_pFrame->getRootFrame(), SwListRedlineType::ORIGTEXT) );
 
-                    if ( !aText.isEmpty() || !aHiddenText.isEmpty() )
+                    if ( !aTextNow.isEmpty() || !aOriginalText.isEmpty() )
                     {
+
                         bool bDisplayChangedParagraphNumbering = 
officecfg::Office::Writer::Comparison::DisplayChangedParagraphNumbering::get();
-                        if (bDisplayChangedParagraphNumbering && aText != 
aHiddenText && !aHiddenText.isEmpty())
+                        if (bDisplayChangedParagraphNumbering && aTextNow != 
aOriginalText && !aOriginalText.isEmpty())
                         {
                             bHasHiddenNum = true;
                             // show also original number after the actual one 
enclosed in [ and ],
                             // and replace tabulator with space to avoid messy 
indentation
                             // resulted by the longer numbering, e.g. "1.[2.]" 
instead of "1.".
-                            aText = aText +  "[" + aHiddenText + "]"
+                            aTextNow = aTextNow +  "[" + aOriginalText + "]"
                                      + 
pTextNd->GetLabelFollowedBy().replaceAll("      ", " ");
                         }
-                        else if (!aText.isEmpty())
-                            aText += pTextNd->GetLabelFollowedBy();
+                        else if (!aTextNow.isEmpty())
+                            aTextNow += pTextNd->GetLabelFollowedBy();
                     }
                 }
                 else if 
(pTextNd->getIDocumentSettingAccess()->get(DocumentSettingId::NO_NUMBERING_SHOW_FOLLOWBY)
-                    || !aText.isEmpty())
-                    aText += pTextNd->GetLabelFollowedBy();
+                    || !aTextNow.isEmpty())
+                    aTextNow += pTextNd->GetLabelFollowedBy();
 
                 // Not just an optimization ...
                 // A number portion without text will be assigned a width of 0.
                 // The succeeding text portion will flow into the BreakCut in 
the BreakLine,
                 // although  we have rInf.GetLast()->GetFlyPortion()!
-                if( !aText.isEmpty() )
+                if( !aTextNow.isEmpty() )
                 {
 
                     // Build a new numbering font basing on the current 
paragraph font:
@@ -702,7 +704,7 @@ SwNumberPortion *SwTextFormatter::NewNumberPortion( 
SwTextFormatInfo &rInf ) con
                     // we do not allow a vertical font
                     pNumFnt->SetVertical( pNumFnt->GetOrientation(), 
m_pFrame->IsVertical() );
 
-                    pRet = new SwNumberPortion( aText, std::move(pNumFnt),
+                    pRet = new SwNumberPortion( aTextNow, std::move(pNumFnt),
                                                 bLeft, bCenter, nMinDist,
                                                 
bLabelAlignmentPosAndSpaceModeActive );
                 }
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 108994515b8d..ed2c8b19ac83 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -4565,6 +4565,17 @@ void SwTextNode::AddToList()
             SwRedlineTable::size_type nRedlPosDel = 
GetDoc().getIDocumentRedlineAccess().GetRedlinePos(*this, RedlineType::Delete);
             if ( SwRedlineTable::npos == nRedlPosDel )
                 AddToListRLHidden();
+            else
+            {
+                const SwNodeOffset nNdIdx = GetIndex();
+                const SwRangeRedline* pTmp = rRedTable[nRedlPosDel];
+                const SwPosition* pRStt = pTmp->Start();
+                if (pRStt->GetNodeIndex() >= nNdIdx)
+                {
+                    // paragraph is partly deleted, add to the "hidden" list, 
too
+                    AddToListRLHidden();
+                }
+            }
         }
         // inserted paragraph, e.g. during file load, add to the "hidden" list
         else if ( SwRedlineTable::npos != nRedlPos )

Reply via email to