summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-05-19 13:40:49 +0500
committerXisco Fauli <xiscofauli@libreoffice.org>2024-05-21 11:27:26 +0200
commite9e27cc9a8914e97f5ea28de863e580062e030de (patch)
treeb71e2dad65519fdf0f627ac62a05844ded39c26e /sw
parent594f0cfa7f1b7b87e95f1e07af9bc54e36dbfbdf (diff)
tdf#161172: Also record history for !bChangeOfListStyleAtParagraph
Change-Id: I6443d7ef76a27ac3ab75f88edd271a8b36e06c14 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167839 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Jenkins Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167818
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/uiwriter/data/tdf161172.fodt35
-rw-r--r--sw/qa/extras/uiwriter/uiwriter9.cxx42
-rw-r--r--sw/source/core/doc/docfmt.cxx10
3 files changed, 81 insertions, 6 deletions
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 fe69b26dd87a..2389aa63714a 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>
@@ -214,6 +215,47 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf160898)
pWrtShell->SelAll();
}
+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