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 f71f72e2876e8d1b7282381917921a77d36385b7
Author:     Bayram Çiçek <[email protected]>
AuthorDate: Tue Jun 17 10:38:59 2025 +0300
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Jan 30 08:39:33 2026 +0100

    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 <[email protected]>
    Change-Id: Ia8852eb7d61b57f15a037b2ffd3e6eec363f90af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186999
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Andras Timar <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198369
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Miklos Vajna <[email protected]>

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 d7fcbb7b5625..6ded5342d88b 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -608,6 +608,20 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, 
testRedlineNumbering2)
     assertXPathContent(pXmlDoc, "/metafile/push/push/push/textarray[7]/text", 
u"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",
+                "expand", u"1.");
+    assertXPath(pXmlDoc, 
"/root/page/body/txt[2]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"2.");
+    assertXPath(pXmlDoc, 
"/root/page/body/txt[3]/SwParaPortion/SwLineLayout/SwFieldPortion",
+                "expand", u"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 a9406f55740c..7b5c1b407af6 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -630,38 +630,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:
@@ -690,7 +692,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 cf12aaa229d1..bd97b31ab290 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -4563,6 +4563,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