sw/qa/extras/uiwriter/data/tdf153636.odt |binary
 sw/qa/extras/uiwriter/uiwriter8.cxx      |   29 +++++++++++++++++++++++++++++
 sw/source/core/doc/doctxm.cxx            |   19 +++++++++++--------
 3 files changed, 40 insertions(+), 8 deletions(-)

New commits:
commit 2a2c4dddf51c0d6ab726a8854123887bbfa7792a
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Tue Oct 29 12:11:41 2024 +0100
Commit:     Andreas Heinisch <andreas.heini...@yahoo.de>
CommitDate: Tue Nov 5 07:44:30 2024 +0100

    tdf#153636 - Search for outline node only if index is for the current 
chapter
    
    Otherwise, "Use level from source chapter" does not work for Graphics and 
Frames in user-defined indices.
    
    Change-Id: I148a097276cf8a60d69a208266ceb9def0444654
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175783
    Tested-by: Jenkins
    Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de>

diff --git a/sw/qa/extras/uiwriter/data/tdf153636.odt 
b/sw/qa/extras/uiwriter/data/tdf153636.odt
new file mode 100644
index 000000000000..d2380120d39e
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf153636.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx 
b/sw/qa/extras/uiwriter/uiwriter8.cxx
index de35df5d570e..1c09ab6a9ad6 100644
--- a/sw/qa/extras/uiwriter/uiwriter8.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter8.cxx
@@ -2896,6 +2896,35 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf151462)
                 "portion", u"another sub three");
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf153636)
+{
+    createSwDoc("tdf153636.odt");
+    dispatchCommand(mxComponent, u".uno:UpdateAllIndexes"_ustr, {});
+    saveAndReload(u"writer8"_ustr);
+
+    xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
+    CPPUNIT_ASSERT(pXmlDoc);
+
+    for (int i = 1; i <= 3; i += 2)
+    {
+        const OUString frameStyleName
+            = getXPath(pXmlDoc,
+                       "/office:document-content/office:body/office:text/"
+                       
"text:user-index[@text:name='User-Defined1']/text:index-body/text:p["
+                           + OString::number(i) + "]",
+                       "style-name");
+        const OUString tableStyleName
+            = getXPath(pXmlDoc,
+                       "/office:document-content/office:body/office:text/"
+                       
"text:user-index[@text:name='User-Defined1']/text:index-body/text:p["
+                           + OString::number(i + 1) + "]",
+                       "style-name");
+
+        // Without the fix in place, the frame and table indentation would 
differ
+        CPPUNIT_ASSERT_EQUAL(frameStyleName, tableStyleName);
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf157129)
 {
     // Unit test for tdf#157129
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 9f9f245a758c..75b29613d227 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -743,8 +743,9 @@ bool SwDoc::SetTOXBaseName(const SwTOXBase& rTOXBase, const 
OUString& rName)
     return false;
 }
 
-static const SwTextNode* lcl_FindChapterNode( const SwNode& rNd,
-        SwRootFrame const*const pLayout, sal_uInt8 const nLvl = 0 )
+static const SwTextNode* lcl_FindChapterNode(const SwNode& rNd, SwRootFrame 
const* const pLayout,
+                                             sal_uInt8 const nLvl = 0,
+                                             const bool bIsFromChapter = true)
 {
     const SwNode* pNd = &rNd;
     if( pNd->GetNodes().GetEndOfExtras().GetIndex() > pNd->GetIndex() )
@@ -759,8 +760,10 @@ static const SwTextNode* lcl_FindChapterNode( const 
SwNode& rNd,
             SwPosition aPos( *pNd );
             pNd = GetBodyTextNode( pNd->GetDoc(), aPos, *pFrame );
             OSL_ENSURE( pNd, "Where's the paragraph?" );
-            // tdf#151462 - search for outline node containing the current node
-            return pNd ? pNd->FindOutlineNodeOfLevel(pNd->GetSectionLevel() - 
1, pLayout) : nullptr;
+            // tdf#153636 - search for outline node only if the index is for 
the current chapter
+            if (bIsFromChapter)
+                // tdf#151462 - search for outline node containing the current 
node
+                return pNd->FindOutlineNodeOfLevel(pNd->GetSectionLevel() - 1, 
pLayout);
         }
     }
     return pNd->FindOutlineNodeOfLevel(nLvl, pLayout);
@@ -1638,8 +1641,8 @@ void SwTOXBaseSection::UpdateContent( SwTOXElement 
eMyType,
                     TOX_ILLUSTRATIONS != SwTOXBase::GetType() &&
                     TOX_OBJECTS != SwTOXBase::GetType() )
             {
-                const SwTextNode* pOutlNd = ::lcl_FindChapterNode( *pCNd,
-                                                pLayout, MAXLEVEL - 1);
+                const SwTextNode* pOutlNd
+                    = ::lcl_FindChapterNode(*pCNd, pLayout, MAXLEVEL - 1, 
IsFromChapter());
                 if( pOutlNd )
                 {
                     if( 
pOutlNd->GetTextColl()->IsAssignedToListLevelOfOutlineStyle())
@@ -1697,8 +1700,8 @@ void SwTOXBaseSection::UpdateTable(const SwTextNode* 
pOwnChapterNode,
                     std::unique_ptr<SwTOXTable> pNew(new SwTOXTable( *pCNd ));
                     if( IsLevelFromChapter() && TOX_TABLES != 
SwTOXBase::GetType())
                     {
-                        const SwTextNode* pOutlNd =
-                            ::lcl_FindChapterNode(*pCNd, pLayout, MAXLEVEL - 
1);
+                        const SwTextNode* pOutlNd
+                            = ::lcl_FindChapterNode(*pCNd, pLayout, MAXLEVEL - 
1, IsFromChapter());
                         if( pOutlNd )
                         {
                             if( 
pOutlNd->GetTextColl()->IsAssignedToListLevelOfOutlineStyle())

Reply via email to