sw/CppunitTest_sw_uiwriter11.mk                       |   18 ++++
 sw/Module_sw.mk                                       |    1 
 sw/qa/extras/uiwriter/data/tdf167760_numberedPara.odt |binary
 sw/qa/extras/uiwriter/uiwriter11.cxx                  |   72 ++++++++++++++++++
 sw/source/uibase/app/docst.cxx                        |    7 +
 5 files changed, 97 insertions(+), 1 deletion(-)

New commits:
commit d008800730c65374ccd05cc7332a2d5f23e7663f
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Wed Aug 27 15:45:58 2025 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Thu Aug 28 12:29:12 2025 +0200

    tdf#167760 tdf#162326 limit reset para list attrs on style apply
    
    Problem: applying any para style
    was removing all numbering or bullets.
    
    This fixes a 25.2 regression from
    commit 075560420a7aa238182e2d80dfe1c5fbaad3edbd
      tdf#162326 reset paragraph list attributes on style apply
    
    The problem is that bResetListAttrs was already set to true,
    but the conditions under which bResetListAttrs applies
    were changed by the above commit
    so now it affects situations it was never intended to match.
    
    Specifically, this was the condition that changed:
    -    && pFormat->GetItemState(RES_PARATR_NUMRULE) == SfxItemState::SET
    +    && pCNd->GetTextNode()->IsInList()
    
    So two changes need to happen here:
    1.) bResetListAttrs needs to only be set
    under the existing comment's stated condition (docst.cxx/doc.hxx)
    that the para style itself contains a numbering rule.
    
    2.) When the control key is held down,
    then bRestListAttrs needs to be set to true
    (which is the stated intention of the above commit).
    
    Possibly #1 should also be done for SwDocShell::MakeInlineHeading,
    but that entire concept is just weird... so who knows.
    
    make CppunitTest_sw_uiwriter11 \
        CPPUNIT_TEST_NAME=testTdf167760_numberedPara
    
    Change-Id: Iae646124a8a434dd3b49a75caeae4bb360396a49
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190309
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins

diff --git a/sw/CppunitTest_sw_uiwriter11.mk b/sw/CppunitTest_sw_uiwriter11.mk
new file mode 100644
index 000000000000..f99c2779507c
--- /dev/null
+++ b/sw/CppunitTest_sw_uiwriter11.mk
@@ -0,0 +1,18 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call sw_uiwriter_test,11))
+
+ifneq ($(filter MORE_FONTS,$(BUILD_TYPE)),)
+$(eval $(call gb_CppunitTest_set_non_application_font_use,sw_uiwriter11,abort))
+endif
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 565b27915c91..d0b8b48f6254 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -138,6 +138,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_uiwriter8 \
     CppunitTest_sw_uiwriter9 \
     CppunitTest_sw_uiwriter10 \
+    CppunitTest_sw_uiwriter11 \
     CppunitTest_sw_layoutwriter \
     CppunitTest_sw_layoutwriter2 \
     CppunitTest_sw_layoutwriter3 \
diff --git a/sw/qa/extras/uiwriter/data/tdf167760_numberedPara.odt 
b/sw/qa/extras/uiwriter/data/tdf167760_numberedPara.odt
new file mode 100644
index 000000000000..def837bbe457
Binary files /dev/null and 
b/sw/qa/extras/uiwriter/data/tdf167760_numberedPara.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter11.cxx 
b/sw/qa/extras/uiwriter/uiwriter11.cxx
new file mode 100644
index 000000000000..4fa9f14f4238
--- /dev/null
+++ b/sw/qa/extras/uiwriter/uiwriter11.cxx
@@ -0,0 +1,72 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+#include <vcl/scheduler.hxx>
+
+#include <comphelper/propertyvalue.hxx>
+#include <comphelper/sequence.hxx>
+#include <comphelper/scopeguard.hxx>
+#include <comphelper/configuration.hxx>
+
+#include <edtwin.hxx>
+#include <view.hxx>
+#include <wrtsh.hxx>
+#include <unotxdoc.hxx>
+#include <ndtxt.hxx>
+#include <IDocumentLayoutAccess.hxx>
+#include <svx/svxids.hrc>
+
+namespace
+{
+class SwUiWriterTest11 : public SwModelTestBase
+{
+public:
+    SwUiWriterTest11()
+        : SwModelTestBase(u"/sw/qa/extras/uiwriter/data/"_ustr)
+    {
+    }
+};
+
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest11, testTdf167760_numberedPara)
+{
+    createSwDoc("tdf167760_numberedPara.odt");
+
+    CPPUNIT_ASSERT_EQUAL(OUString("1.1."),
+                         getProperty<OUString>(getParagraph(1), 
"ListLabelString"));
+
+    // apply a non-numbered style to paragraph 1
+    dispatchCommand(mxComponent, u".uno:StyleApply"_ustr,
+                    { comphelper::makePropertyValue(u"FamilyName"_ustr, 
u"ParagraphStyles"_ustr),
+                      comphelper::makePropertyValue(u"Style"_ustr, u"Text 
body"_ustr) });
+    // the numbering should not be affected by changing a paragraph style
+    CPPUNIT_ASSERT_EQUAL(OUString("1.1."),
+                         getProperty<OUString>(getParagraph(1), 
"ListLabelString"));
+
+    // apply a numbered style
+    dispatchCommand(mxComponent, u".uno:StyleApply"_ustr,
+                    { comphelper::makePropertyValue(u"FamilyName"_ustr, 
u"ParagraphStyles"_ustr),
+                      comphelper::makePropertyValue(u"Style"_ustr, 
u"aList"_ustr) });
+    // the numbering should be changed to that specified by the paragraph style
+    CPPUNIT_ASSERT_EQUAL(OUString("i.I.a)"),
+                         getProperty<OUString>(getParagraph(1), 
"ListLabelString"));
+
+    // apply the non-numbered style while holding down the Ctrl-key
+    dispatchCommand(mxComponent, u".uno:StyleApply"_ustr,
+                    { comphelper::makePropertyValue(u"FamilyName"_ustr, 
u"ParagraphStyles"_ustr),
+                      comphelper::makePropertyValue(u"Style"_ustr, u"Text 
body"_ustr),
+                      comphelper::makePropertyValue(u"KeyModifier"_ustr, 
uno::Any(KEY_MOD1)) });
+    // the numbering should be removed when the Ctrl-key is held down
+    CPPUNIT_ASSERT_EQUAL(OUString(), getProperty<OUString>(getParagraph(1), 
"ListLabelString"));
+}
+
+} // end of anonymous namespace
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index 995c005e964e..37f3d8a35220 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -1292,7 +1292,12 @@ SfxStyleFamily SwDocShell::ApplyStyles(const OUString 
&rName, SfxStyleFamily nFa
                 // #i62675#
                 // clear also list attributes at affected text nodes, if 
paragraph
                 // style has the list style attribute set.
-                pSh->SetTextFormatColl( pColl, true, (nMode & KEY_MOD1) ? 
SetAttrMode::REMOVE_ALL_ATTR : SetAttrMode::DEFAULT);
+                const SetAttrMode nAttrModeFlag
+                    = (nMode & KEY_MOD1) ? SetAttrMode::REMOVE_ALL_ATTR : 
SetAttrMode::DEFAULT;
+                const bool bResetListAttrs
+                    = nAttrModeFlag == SetAttrMode::REMOVE_ALL_ATTR
+                      || (pColl && pColl->GetItemState(RES_PARATR_NUMRULE) == 
SfxItemState::SET);
+                pSh->SetTextFormatColl(pColl, bResetListAttrs, nAttrModeFlag);
             }
             break;
         }

Reply via email to