sw/qa/extras/uiwriter/data/tdf161172.fodt |   35 +++++++++++++++++++++++++
 sw/qa/extras/uiwriter/uiwriter9.cxx       |   41 ++++++++++++++++++++++++++++++
 sw/source/core/doc/docfmt.cxx             |   10 ++-----
 3 files changed, 80 insertions(+), 6 deletions(-)

New commits:
commit af38e96cad0949291a289443363218f93ba59ecd
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun May 19 13:40:49 2024 +0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue May 21 14:01:59 2024 +0200

    tdf#161172: Also record history for !bChangeOfListStyleAtParagraph
    
    Change-Id: I6443d7ef76a27ac3ab75f88edd271a8b36e06c14
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167839
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167841
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sw/qa/extras/uiwriter/data/tdf161172.fodt 
b/sw/qa/extras/uiwriter/data/tdf161172.fodt
new file mode 100644
index 000000000000..08cea575cc60
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf161172.fodt
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:styles>
+  <style:style style:name="Num_1_lvl2" style:family="paragraph" 
style:list-style-name="Num_1" style:list-level="2"/>
+  <style:style style:name="No_list" style:family="paragraph" 
style:list-style-name=""/>
+  <text:list-style style:name="Num_1">
+   <text:list-level-style-number text:level="1" style:num-prefix="Num1_lvl1_" 
style:num-format="1">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="space"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="2" style:num-prefix="Num1_lvl2_" 
style:num-format="1">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="space"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+  </text:list-style>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="No_list" style:list-style-name="Num_1"/>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:list text:style-name="Num_1">
+    <text:list-item>
+     <text:p text:style-name="P1">foo</text:p>
+    </text:list-item>
+   </text:list>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx 
b/sw/qa/extras/uiwriter/uiwriter9.cxx
index ecf35075623e..335b004fa6f8 100644
--- a/sw/qa/extras/uiwriter/uiwriter9.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter9.cxx
@@ -19,6 +19,7 @@
 #include <com/sun/star/view/XSelectionSupplier.hpp>
 
 #include <comphelper/propertysequence.hxx>
+#include <comphelper/propertyvalue.hxx>
 #include <swdtflvr.hxx>
 #include <o3tl/string_view.hxx>
 
@@ -256,6 +257,46 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, 
testTdf159054_disableOutlineNumbering)
     CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xPara2, 
"ListLabelString"));
     CPPUNIT_ASSERT_EQUAL(OUString("A."), getProperty<OUString>(xPara3, 
"ListLabelString"));
 }
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf161172)
+{
+    // Given a paragraph manually made a member of a list:
+    createSwDoc("tdf161172.fodt");
+    auto para = getParagraph(1);
+
+    // Check initial state: the first paragraph has "No_list" para style, 
"Num_1" numbering style,
+    // numbering level 0, and "Num1_lvl1_1" numbering label.
+    CPPUNIT_ASSERT_EQUAL(u"No_list"_ustr, getProperty<OUString>(para, 
u"ParaStyleName"_ustr));
+    CPPUNIT_ASSERT_EQUAL(u"Num_1"_ustr, getProperty<OUString>(para, 
u"NumberingStyleName"_ustr));
+    CPPUNIT_ASSERT_EQUAL(u"Num1_lvl1_1"_ustr, getProperty<OUString>(para, 
u"ListLabelString"_ustr));
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getProperty<sal_Int16>(para, 
u"NumberingLevel"_ustr));
+
+    // Assign "Num_1_lvl2" paragraph style to the first paragraph. The style 
is associated with
+    // "Num_1" numbering style, level 1.
+    dispatchCommand(mxComponent, u".uno:StyleApply"_ustr,
+                    { comphelper::makePropertyValue(u"FamilyName"_ustr, 
u"ParagraphStyles"_ustr),
+                      comphelper::makePropertyValue(u"Style"_ustr, 
u"Num_1_lvl2"_ustr) });
+
+    // Check that the respective properties got correctly applied
+    CPPUNIT_ASSERT_EQUAL(u"Num_1_lvl2"_ustr, getProperty<OUString>(para, 
u"ParaStyleName"_ustr));
+    CPPUNIT_ASSERT_EQUAL(u"Num_1"_ustr, getProperty<OUString>(para, 
u"NumberingStyleName"_ustr));
+    CPPUNIT_ASSERT_EQUAL(u"Num1_lvl2_1"_ustr, getProperty<OUString>(para, 
u"ListLabelString"_ustr));
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(1), getProperty<sal_Int16>(para, 
u"NumberingLevel"_ustr));
+
+    // Undo
+    dispatchCommand(mxComponent, u".uno:Undo"_ustr, {});
+
+    // Check that the numbering properties got correctly restored
+    CPPUNIT_ASSERT_EQUAL(u"No_list"_ustr, getProperty<OUString>(para, 
u"ParaStyleName"_ustr));
+    CPPUNIT_ASSERT_EQUAL(u"Num_1"_ustr, getProperty<OUString>(para, 
u"NumberingStyleName"_ustr));
+    // Without the fix, this would fail with
+    // - Expected: Num1_lvl1_1
+    // - Actual  : Num1_lvl2_1
+    CPPUNIT_ASSERT_EQUAL(u"Num1_lvl1_1"_ustr, getProperty<OUString>(para, 
u"ListLabelString"_ustr));
+    // Without the fix, this would fail with
+    // - Expected: 0
+    // - Actual  : 1
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getProperty<sal_Int16>(para, 
u"NumberingLevel"_ustr));
+}
 
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 1c696bebb6a0..3390a506052c 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -1040,14 +1040,12 @@ static bool lcl_SetTextFormatColl( SwNode* pNode, void* 
pArgs )
                 }
             }
 
+            std::optional<SwRegHistory> oRegH;
+            if (pPara->pHistory)
+                oRegH.emplace(&rTNd, rTNd, pPara->pHistory);
+
             if ( bChangeOfListStyleAtParagraph )
             {
-                std::unique_ptr< SwRegHistory > pRegH;
-                if ( pPara->pHistory )
-                {
-                    pRegH.reset(new SwRegHistory(&rTNd, rTNd, 
pPara->pHistory));
-                }
-
                 pCNd->ResetAttr( RES_PARATR_NUMRULE );
 
                 // reset all list attributes

Reply via email to