sw/inc/doc.hxx                                          |   30 +-
 sw/qa/extras/uiwriter/data/stylewithlistandindents.fodt |  182 ++++++++++++++++
 sw/qa/extras/uiwriter/uiwriter8.cxx                     |  121 ++++++++++
 sw/source/core/doc/DocumentContentOperationsManager.cxx |   16 +
 sw/source/core/doc/docnum.cxx                           |   98 +++++++-
 sw/source/core/edit/autofmt.cxx                         |    2 
 sw/source/core/edit/ednumber.cxx                        |   12 -
 sw/source/core/undo/unnum.cxx                           |    4 
 sw/source/core/unocore/unocrsrhelper.cxx                |    8 
 sw/source/filter/basflt/fltshell.cxx                    |    2 
 10 files changed, 433 insertions(+), 42 deletions(-)

New commits:
commit b01d89eaf473870281f6ecbdeb12aa3fcd79f9bb
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri May 17 13:58:41 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sat May 18 22:30:14 2024 +0200

    tdf#161137 sw: AutoText or Paste should copy paragraph indents for lists
    
    The first commit made the start and end node of the paste look like the
    list it was inserted into, but the middle nodes may have different
    paragraph styles and may have different left margin / first line indent.
    
    In addition to the SwNumRule, also copy any left margin or first line
    indent if it is effective on the node that the SwNumRule was taken from.
    
    Now all the list labels should be in the same place.
    
    Change-Id: Ia5794687ea0ff542f23289b1ca63ea99dae85bc3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167777
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 2bcaa374ea418cd81f9dbf62cd7e896f5977992a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167810
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 84378f8521ea..946c96fd29db 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1073,7 +1073,9 @@ public:
                      const SwNumRule&,
                      SetNumRuleMode mode,
                      SwRootFrame const* pLayout = nullptr,
-                     const OUString& sContinuedListId = OUString());
+                     const OUString& sContinuedListId = OUString(),
+                     SvxTextLeftMarginItem const* pTextLeftMarginToPropagate = 
nullptr,
+                     SvxFirstLineIndentItem const* pFirstLineIndentToPropagate 
= nullptr);
     void SetCounted(const SwPaM&, bool bCounted, SwRootFrame const* pLayout);
 
     void MakeUniqueNumRules(const SwPaM & rPaM);
@@ -1150,7 +1152,9 @@ public:
                                     int nNonEmptyAllowed,
                                     OUString& sListId,
                                     SwRootFrame const* pLayout,
-                                    const bool bInvestigateStartNode = false );
+                                    const bool bInvestigateStartNode = false,
+                                    SvxTextLeftMarginItem const** 
o_ppTextLeftMargin = nullptr,
+                                    SvxFirstLineIndentItem const** 
o_ppFirstLineIndent = nullptr);
 
     // Paragraphs without numbering but with indents.
     bool NoNum( const SwPaM& );
diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx 
b/sw/qa/extras/uiwriter/uiwriter8.cxx
index 13e437e68d96..60b1bd8e9ce6 100644
--- a/sw/qa/extras/uiwriter/uiwriter8.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter8.cxx
@@ -25,6 +25,7 @@
 #include <frameformats.hxx>
 #include <tools/json_writer.hxx>
 #include <unotools/streamwrap.hxx>
+#include <editeng/lrspitem.hxx>
 #include <sfx2/linkmgr.hxx>
 
 #include <wrtsh.hxx>
@@ -880,7 +881,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, 
testInsertAutoTextIntoListFromParaStyle)
     pWrtShell->FwdPara();
     pWrtShell->EndPara(/*bSelect=*/false);
     // expands autotext (via F3)
-    pWrtShell->Insert(" dt");
+    pWrtShell->Insert(" jacr");
 
     SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
     pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_F3);
@@ -889,6 +890,10 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, 
testInsertAutoTextIntoListFromParaStyle)
     pWrtShell->SttEndDoc(/*bStt=*/true);
     pWrtShell->FwdPara();
 
+    SwNumRule* pNumRule;
+    SvxTextLeftMarginItem const* pTextLeftMargin;
+    SvxFirstLineIndentItem const* pFirstLineIndent;
+
     {
         SwTextNode& rNode{ 
*pWrtShell->GetCursor()->GetPoint()->GetNode().GetTextNode() };
         // numrule from paragraph style, but not from direct formatting
@@ -905,7 +910,32 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, 
testInsertAutoTextIntoListFromParaStyle)
         CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, false));
         CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, true));
         CPPUNIT_ASSERT_EQUAL(u"ListAndIndents"_ustr, 
rNode.GetTextColl()->GetName());
-        CPPUNIT_ASSERT(rNode.GetText().startsWith("Item He heard quiet 
steps"));
+        CPPUNIT_ASSERT_EQUAL(u"Item We confirm receipt of your application 
material."_ustr,
+                             rNode.GetText());
+        pNumRule = rNode.GetNumRule();
+        pTextLeftMargin = &rNode.GetAttr(RES_MARGIN_TEXTLEFT);
+        pFirstLineIndent = &rNode.GetAttr(RES_MARGIN_FIRSTLINE);
+    }
+
+    pWrtShell->FwdPara();
+
+    {
+        SwTextNode& rNode{ 
*pWrtShell->GetCursor()->GetPoint()->GetNode().GetTextNode() };
+        auto pSet{ rNode.GetpSwAttrSet() };
+        CPPUNIT_ASSERT(pSet);
+        // list id was set
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_PARATR_LIST_ID, false));
+        // middle paragraph was pasted - has numrule and indents applied 
directly
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_PARATR_NUMRULE, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_FIRSTLINE, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, false));
+        CPPUNIT_ASSERT_EQUAL(u"Default Paragraph Style"_ustr, 
rNode.GetTextColl()->GetName());
+        CPPUNIT_ASSERT(rNode.GetText().startsWith("As more applicants 
applied"));
+        CPPUNIT_ASSERT_EQUAL(pNumRule, rNode.GetNumRule());
+        CPPUNIT_ASSERT_EQUAL(pTextLeftMargin->GetTextLeft(),
+                             rNode.GetAttr(RES_MARGIN_TEXTLEFT).GetTextLeft());
+        CPPUNIT_ASSERT_EQUAL(pFirstLineIndent->GetTextFirstLineOffset(),
+                             
rNode.GetAttr(RES_MARGIN_FIRSTLINE).GetTextFirstLineOffset());
     }
 
     pWrtShell->FwdPara();
@@ -926,7 +956,12 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, 
testInsertAutoTextIntoListFromParaStyle)
         CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, false));
         CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, true));
         CPPUNIT_ASSERT_EQUAL(u"ListAndIndents"_ustr, 
rNode.GetTextColl()->GetName());
-        CPPUNIT_ASSERT_EQUAL(u""_ustr, rNode.GetText()); // this is a new 
empty paragraph
+        CPPUNIT_ASSERT(rNode.GetText().endsWith("as soon as we have come to a 
decision."));
+        CPPUNIT_ASSERT_EQUAL(pNumRule, rNode.GetNumRule());
+        CPPUNIT_ASSERT_EQUAL(pTextLeftMargin->GetTextLeft(),
+                             rNode.GetAttr(RES_MARGIN_TEXTLEFT).GetTextLeft());
+        CPPUNIT_ASSERT_EQUAL(pFirstLineIndent->GetTextFirstLineOffset(),
+                             
rNode.GetAttr(RES_MARGIN_FIRSTLINE).GetTextFirstLineOffset());
     }
 
     pWrtShell->FwdPara();
@@ -948,6 +983,11 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, 
testInsertAutoTextIntoListFromParaStyle)
         CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, true));
         CPPUNIT_ASSERT_EQUAL(u"ListAndIndents"_ustr, 
rNode.GetTextColl()->GetName());
         CPPUNIT_ASSERT_EQUAL(u"more"_ustr, rNode.GetText()); // pre-exising 
list item
+        CPPUNIT_ASSERT_EQUAL(pNumRule, rNode.GetNumRule());
+        CPPUNIT_ASSERT_EQUAL(pTextLeftMargin->GetTextLeft(),
+                             rNode.GetAttr(RES_MARGIN_TEXTLEFT).GetTextLeft());
+        CPPUNIT_ASSERT_EQUAL(pFirstLineIndent->GetTextFirstLineOffset(),
+                             
rNode.GetAttr(RES_MARGIN_FIRSTLINE).GetTextFirstLineOffset());
     }
 }
 
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 832d03d67c1e..234d73aecb05 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -5107,12 +5107,16 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
     // bullet list.
     // Keep also the <ListId> value for possible propagation.
     OUString aListIdToPropagate;
+    SvxTextLeftMarginItem const* pTextLeftMarginToPropagate{nullptr};
+    SvxFirstLineIndentItem const* pFirstLineIndentToPropagate{nullptr};
     const SwNumRule* pNumRuleToPropagate =
-        rDoc.SearchNumRule( rPos, false, true, false, 0, aListIdToPropagate, 
nullptr, true );
+        rDoc.SearchNumRule(rPos, false, true, false, 0, aListIdToPropagate, 
nullptr,
+                true, &pTextLeftMarginToPropagate, 
&pFirstLineIndentToPropagate);
     if ( !pNumRuleToPropagate )
     {
         pNumRuleToPropagate =
-            rDoc.SearchNumRule( rPos, false, false, false, 0, 
aListIdToPropagate, nullptr, true );
+            rDoc.SearchNumRule(rPos, false, false, false, 0, 
aListIdToPropagate, nullptr,
+                true, &pTextLeftMarginToPropagate, 
&pFirstLineIndentToPropagate);
     }
     // #i86492#
     // Do not propagate previous found list, if
@@ -5522,7 +5526,8 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
         // the paragraph style, in that case applying it again in mpAttrSet 
could
         // override indents, so avoid that.
         rDoc.SetNumRule(*pCopyPam, *pNumRuleToPropagate,
-            SwDoc::SetNumRuleMode::DontSetIfAlreadyApplied, nullptr, 
aListIdToPropagate);
+            SwDoc::SetNumRuleMode::DontSetIfAlreadyApplied, nullptr, 
aListIdToPropagate,
+            pTextLeftMarginToPropagate, pFirstLineIndentToPropagate);
     }
 
     rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index 2a777528f4e9..01c4a1b3874a 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -46,6 +46,7 @@
 #include <SwNodeNum.hxx>
 #include <list.hxx>
 #include <calbck.hxx>
+#include <editeng/lrspitem.hxx>
 #include <comphelper/string.hxx>
 #include <comphelper/random.hxx>
 #include <o3tl/safeint.hxx>
@@ -862,7 +863,9 @@ OUString SwDoc::SetNumRule( const SwPaM& rPam,
                         const SwNumRule& rRule,
                         SetNumRuleMode eMode,
                         SwRootFrame const*const pLayout,
-                        const OUString& sContinuedListId)
+                        const OUString& sContinuedListId,
+                        SvxTextLeftMarginItem const*const 
pTextLeftMarginToPropagate,
+                        SvxFirstLineIndentItem const*const 
pFirstLineIndentToPropagate)
 {
     OUString sListId;
 
@@ -982,6 +985,19 @@ OUString SwDoc::SetNumRule( const SwPaM& rPam,
                         getIDocumentContentOperations().InsertPoolItem(temp,
                                 SwNumRuleItem(pNewOrChangedNumRule->GetName()),
                                 SetAttrMode::DEFAULT, pLayout);
+                        // apply provided margins to get visually same result
+                        if (pTextLeftMarginToPropagate)
+                        {
+                            
getIDocumentContentOperations().InsertPoolItem(temp,
+                                    *pTextLeftMarginToPropagate,
+                                    SetAttrMode::DEFAULT, pLayout);
+                        }
+                        if (pFirstLineIndentToPropagate)
+                        {
+                            
getIDocumentContentOperations().InsertPoolItem(temp,
+                                    *pFirstLineIndentToPropagate,
+                                    SetAttrMode::DEFAULT, pLayout);
+                        }
                     }
                 }
             }
@@ -991,6 +1007,18 @@ OUString SwDoc::SetNumRule( const SwPaM& rPam,
             getIDocumentContentOperations().InsertPoolItem(aPam,
                     SwNumRuleItem(pNewOrChangedNumRule->GetName()),
                     SetAttrMode::DEFAULT, pLayout);
+            if (pTextLeftMarginToPropagate)
+            {
+                getIDocumentContentOperations().InsertPoolItem(aPam,
+                        *pTextLeftMarginToPropagate,
+                        SetAttrMode::DEFAULT, pLayout);
+            }
+            if (pFirstLineIndentToPropagate)
+            {
+                getIDocumentContentOperations().InsertPoolItem(aPam,
+                        *pFirstLineIndentToPropagate,
+                        SetAttrMode::DEFAULT, pLayout);
+            }
         }
     }
 
@@ -1643,7 +1671,9 @@ const SwNumRule *  SwDoc::SearchNumRule(const SwPosition 
& rPos,
                                         int nNonEmptyAllowed,
                                         OUString& sListId,
                                         SwRootFrame const* pLayout,
-                                        const bool bInvestigateStartNode)
+                                        const bool bInvestigateStartNode,
+                                        SvxTextLeftMarginItem const** 
o_ppTextLeftMargin,
+                                        SvxFirstLineIndentItem const** 
o_ppFirstLineIndent)
 {
     const SwNumRule * pResult = nullptr;
     SwTextNode * pTextNd = rPos.GetNode().GetTextNode();
@@ -1680,9 +1710,28 @@ const SwNumRule *  SwDoc::SearchNumRule(const SwPosition 
& rPos,
                          ( ( bNum && pNumRule->Get(0).IsEnumeration()) ||
                            ( !bNum && pNumRule->Get(0).IsItemize() ) ) ) // 
#i22362#, #i29560#
                     {
-                        pResult = pTextNd->GetNumRule();
+                        pResult = pNumRule;
                         // provide also the list id, to which the text node 
belongs.
                         sListId = pTextNd->GetListId();
+                        // also get the margins that override the numrule
+                        int const nListLevel{pTextNd->GetActualListLevel()};
+                        if ((o_ppTextLeftMargin || o_ppFirstLineIndent)
+                            && 0 <= nListLevel
+                            && 
pNumRule->Get(o3tl::narrowing<sal_uInt16>(nListLevel))
+                                .GetPositionAndSpaceMode() == 
SvxNumberFormat::LABEL_ALIGNMENT)
+                        {
+                            ::sw::ListLevelIndents const 
indents{pTextNd->AreListLevelIndentsApplicable()};
+                            if (!(indents & ::sw::ListLevelIndents::LeftMargin)
+                                && o_ppTextLeftMargin)
+                            {
+                                *o_ppTextLeftMargin = 
&pTextNd->SwContentNode::GetAttr(RES_MARGIN_TEXTLEFT);
+                            }
+                            if (!(indents & ::sw::ListLevelIndents::FirstLine)
+                                && o_ppFirstLineIndent)
+                            {
+                                *o_ppFirstLineIndent = 
&pTextNd->SwContentNode::GetAttr(RES_MARGIN_FIRSTLINE);
+                            }
+                        }
                     }
 
                     break;
commit 2e2ea78e585d469373c038aa12c5b99909a018c8
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu May 16 18:09:18 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sat May 18 22:30:01 2024 +0200

    tdf#161137 sw: fix AutoText or Paste overriding paragraph indents
    
    The problem is that when a paragraph style specifies a SwNumRule, then
    this style's indents override the indents of the SwNumRule, but if the
    same SwNumRule is also added to the SwTextNode's mpAttrSet, then the
    style's indents no longer take effect.
    
    This happens both when inserting an AutoText, and when Pasting, into a
    list item, because DocumentContentOperationsManager::CopyImplImpl()
    sets the pNumRuleToPropagate as direct formatting on every pasted node.
    
    Add another flag to SwDoc::SetNumRule() to check if pNumRuleToPropagate
    was already in effect due to the paragraph style.
    
    Change-Id: Id98ad2a21eab4f8636fb36f9298a054cfe4f7784
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167766
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 7698f386413e514a4478a1af69a8a3be93dfecab)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167689
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 99cb33c75826..84378f8521ea 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1052,23 +1052,28 @@ public:
 
     bool GotoOutline(SwPosition& rPos, const OUString& rName, SwRootFrame 
const* = nullptr) const;
 
-    /** Accept changes of outline styles for OutlineRule.
-     @param bResetIndentAttrs Optional parameter - default value false:
-      If <bResetIndentAttrs> equals true, the indent attributes "before text"
-      and "first line indent" are additionally reset at the provided PaM, if
-      the list style makes use of the new list level attributes.
-     @param bCreateNewList indicates if a new list is created by applying the 
given list style.
+    enum class SetNumRuleMode {
+        Default = 0,
+        /// indicates if a new list is created by applying the given list 
style.
+        CreateNewList = 1,
+        DontSetItem = 2,
+        /** If enabled, the indent attributes "before text" and
+          "first line indent" are additionally reset at the provided PaM,
+          if the list style makes use of the new list level attributes. */
+        ResetIndentAttrs = 4,
+        DontSetIfAlreadyApplied = 8
+    };
+
+    /** Set or change numbering rule on text nodes, as direct formatting.
      @param sContinuedListId If bCreateNewList is false, may contain the
       list Id of a list which has to be continued by applying the given list 
style
 
      @return the set ListId if bSetItem is true */
     OUString SetNumRule( const SwPaM&,
                      const SwNumRule&,
-                     bool bCreateNewList,
+                     SetNumRuleMode mode,
                      SwRootFrame const* pLayout = nullptr,
-                     const OUString& sContinuedListId = OUString(),
-                     bool bSetItem = true,
-                     const bool bResetIndentAttrs = false );
+                     const OUString& sContinuedListId = OUString());
     void SetCounted(const SwPaM&, bool bCounted, SwRootFrame const* pLayout);
 
     void MakeUniqueNumRules(const SwPaM & rPaM);
@@ -1704,6 +1709,7 @@ private:
 
 namespace o3tl {
     template<> struct typed_flags<SwDoc::RowColMode> : 
is_typed_flags<SwDoc::RowColMode, 3> {};
+    template<> struct typed_flags<SwDoc::SetNumRuleMode> : 
is_typed_flags<SwDoc::SetNumRuleMode, 0x0f> {};
 }
 
 // This method is called in Dtor of SwDoc and deletes cache of ContourObjects.
diff --git a/sw/qa/extras/uiwriter/data/stylewithlistandindents.fodt 
b/sw/qa/extras/uiwriter/data/stylewithlistandindents.fodt
new file mode 100644
index 000000000000..afb7ae06aac2
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/stylewithlistandindents.fodt
@@ -0,0 +1,182 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:c
 alcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:
 meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ 
<office:meta><meta:creation-date>2024-05-16T18:27:43.913131212</meta:creation-date><dc:date>2024-05-16T18:30:43.721654337</dc:date><meta:editing-duration>PT3M</meta:editing-duration><meta:editing-cycles>1</meta:editing-cycles><meta:document-statistic
 meta:table-count="0" meta:image-count="0" meta:object-count="0" 
meta:page-count="1" meta:paragraph-count="2" meta:word-count="4" 
meta:character-count="12" 
meta:non-whitespace-character-count="12"/><meta:generator>LibreOfficeDev/24.8.0.0.alpha0$Linux_X86_64
 
LibreOffice_project/a2e7a65b22857abc945af33c7673d9d8b50688d5</meta:generator></office:meta>
+ <office:font-face-decls>
+  <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation 
Serif'" style:font-family-generic="roman" style:font-pitch="variable"/>
+  <style:font-face style:name="Noto Sans1" svg:font-family="'Noto Sans'" 
style:font-family-generic="system" style:font-pitch="variable"/>
+  <style:font-face style:name="Noto Serif CJK SC" svg:font-family="'Noto Serif 
CJK SC'" style:font-family-generic="system" style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="graphic">
+   <style:graphic-properties svg:stroke-color="#3465a4" 
draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" 
draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" 
draw:start-line-spacing-vertical="0.283cm" 
draw:end-line-spacing-horizontal="0.283cm" 
draw:end-line-spacing-vertical="0.283cm" style:flow-with-text="false"/>
+   <style:paragraph-properties style:text-autospace="ideograph-alpha" 
style:line-break="strict" loext:tab-stop-distance="0cm" 
style:writing-mode="lr-tb" style:font-independent-line-spacing="false">
+    <style:tab-stops/>
+   </style:paragraph-properties>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="de" fo:country="DE" style:letter-kerning="true" 
style:font-name-asian="Noto Serif CJK SC" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Noto Sans1" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN"/>
+  </style:default-style>
+  <style:default-style style:family="paragraph">
+   <style:paragraph-properties fo:orphans="2" fo:widows="2" 
fo:hyphenation-ladder-count="no-limit" fo:hyphenation-keep="auto" 
style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" 
style:line-break="strict" style:tab-stop-distance="1.251cm" 
style:writing-mode="page"/>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="de" fo:country="DE" style:letter-kerning="true" 
style:font-name-asian="Noto Serif CJK SC" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Noto Sans1" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN" fo:hyphenate="false" 
fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" 
loext:hyphenation-no-caps="false" loext:hyphenation-no-last-word="false" 
loext:hyphenation-word-char-count="5" loext:hyphenation-zone="no-limit" 
loext:hyphenation-keep-type="column"/>
+  </style:default-style>
+  <style:default-style style:family="table">
+   <style:table-properties table:border-model="collapsing"/>
+  </style:default-style>
+  <style:default-style style:family="table-row">
+   <style:table-row-properties fo:keep-together="auto"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text"/>
+  <style:style style:name="Text_20_body" style:display-name="Text body" 
style:family="paragraph" style:parent-style-name="Standard" style:class="text">
+   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.247cm" 
style:contextual-spacing="false" fo:line-height="115%"/>
+  </style:style>
+  <style:style style:name="ListAndIndents" style:family="paragraph" 
style:parent-style-name="Text_20_body" style:list-style-name="Numbering_20_ABC">
+   <style:paragraph-properties fo:margin-left="3cm" fo:text-indent="5.001cm" 
style:auto-text-indent="false"/>
+  </style:style>
+  <style:style style:name="Numbering_20_Symbols" style:display-name="Numbering 
Symbols" style:family="text"/>
+  <text:outline-style style:name="Outline">
+   <text:outline-level-style text:level="1" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="2" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="3" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="4" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="5" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="6" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="7" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="8" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="9" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="10" style:num-format="">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab"/>
+    </style:list-level-properties>
+   </text:outline-level-style>
+  </text:outline-style>
+  <text:list-style style:name="Numbering_20_ABC" style:display-name="Numbering 
ABC">
+   <text:list-level-style-number text:level="1" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%1%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="1.33cm" fo:text-indent="-0.7cm" 
fo:margin-left="1.33cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="2" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%2%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="2.03cm" fo:text-indent="-0.7cm" 
fo:margin-left="2.03cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="3" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%3%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="2.731cm" fo:text-indent="-0.7cm" 
fo:margin-left="2.731cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="4" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%4%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="3.431cm" fo:text-indent="-0.7cm" 
fo:margin-left="3.431cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="5" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%5%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="4.131cm" fo:text-indent="-0.7cm" 
fo:margin-left="4.131cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="6" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%6%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="4.831cm" fo:text-indent="-0.7cm" 
fo:margin-left="4.831cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="7" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%7%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="5.532cm" fo:text-indent="-0.7cm" 
fo:margin-left="5.532cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="8" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%8%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="6.232cm" fo:text-indent="-0.7cm" 
fo:margin-left="6.232cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="9" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%9%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="6.932cm" fo:text-indent="-0.7cm" 
fo:margin-left="6.932cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+   <text:list-level-style-number text:level="10" 
text:style-name="Numbering_20_Symbols" loext:num-list-format="%10%." 
style:num-suffix="." style:num-format="A">
+    <style:list-level-properties 
text:list-level-position-and-space-mode="label-alignment">
+     <style:list-level-label-alignment text:label-followed-by="listtab" 
text:list-tab-stop-position="7.632cm" fo:text-indent="-0.7cm" 
fo:margin-left="7.632cm"/>
+    </style:list-level-properties>
+   </text:list-level-style-number>
+  </text:list-style>
+  <text:notes-configuration text:note-class="footnote" style:num-format="1" 
text:start-value="0" text:footnotes-position="page" 
text:start-numbering-at="document"/>
+  <text:notes-configuration text:note-class="endnote" style:num-format="i" 
text:start-value="0"/>
+  <text:linenumbering-configuration text:number-lines="false" 
text:offset="0.499cm" style:num-format="1" text:number-position="left" 
text:increment="5"/>
+  </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:text-properties/>
+  </style:style>
+  <style:style style:name="P2" style:family="paragraph" 
style:parent-style-name="ListAndIndents">
+   <style:text-properties/>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" 
fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" 
fo:margin-right="2cm" style:writing-mode="lr-tb" 
style:footnote-max-height="0cm" loext:margin-gutter="0cm">
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="solid" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:sequence-decls>
+    <text:sequence-decl text:display-outline-level="0" 
text:name="Illustration"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Figure"/>
+   </text:sequence-decls>
+   <text:p text:style-name="P1"/>
+   <text:list text:style-name="Numbering_20_ABC">
+    <text:list-item>
+     <text:p text:style-name="ListAndIndents">Item</text:p>
+    </text:list-item>
+    <text:list-item>
+     <text:p text:style-name="P2">more</text:p>
+    </text:list-item>
+   </text:list>
+   <text:p text:style-name="Standard"/>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx 
b/sw/qa/extras/uiwriter/uiwriter8.cxx
index 4fa027b0515b..13e437e68d96 100644
--- a/sw/qa/extras/uiwriter/uiwriter8.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter8.cxx
@@ -870,6 +870,87 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf116315)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testInsertAutoTextIntoListFromParaStyle)
+{
+    createSwDoc("stylewithlistandindents.fodt");
+    SwDoc* const pDoc = getSwDoc();
+    SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    CPPUNIT_ASSERT(pWrtShell);
+
+    pWrtShell->FwdPara();
+    pWrtShell->EndPara(/*bSelect=*/false);
+    // expands autotext (via F3)
+    pWrtShell->Insert(" dt");
+
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_F3);
+    Scheduler::ProcessEventsToIdle();
+
+    pWrtShell->SttEndDoc(/*bStt=*/true);
+    pWrtShell->FwdPara();
+
+    {
+        SwTextNode& rNode{ 
*pWrtShell->GetCursor()->GetPoint()->GetNode().GetTextNode() };
+        // numrule from paragraph style, but not from direct formatting
+        auto pSet{ rNode.GetpSwAttrSet() };
+        CPPUNIT_ASSERT(pSet);
+        // list id was set
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_PARATR_LIST_ID, false));
+        // the numrule is set on the paragraph style, not on the paragraph
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, 
pSet->GetItemState(RES_PARATR_NUMRULE, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_PARATR_NUMRULE, true));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
+                             pSet->GetItemState(RES_MARGIN_FIRSTLINE, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_FIRSTLINE, true));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, true));
+        CPPUNIT_ASSERT_EQUAL(u"ListAndIndents"_ustr, 
rNode.GetTextColl()->GetName());
+        CPPUNIT_ASSERT(rNode.GetText().startsWith("Item He heard quiet 
steps"));
+    }
+
+    pWrtShell->FwdPara();
+
+    {
+        SwTextNode& rNode{ 
*pWrtShell->GetCursor()->GetPoint()->GetNode().GetTextNode() };
+        // numrule from paragraph style, but not from direct formatting
+        auto pSet{ rNode.GetpSwAttrSet() };
+        CPPUNIT_ASSERT(pSet);
+        // list id was set
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_PARATR_LIST_ID, false));
+        // the numrule is set on the paragraph style, not on the paragraph
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, 
pSet->GetItemState(RES_PARATR_NUMRULE, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_PARATR_NUMRULE, true));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
+                             pSet->GetItemState(RES_MARGIN_FIRSTLINE, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_FIRSTLINE, true));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, true));
+        CPPUNIT_ASSERT_EQUAL(u"ListAndIndents"_ustr, 
rNode.GetTextColl()->GetName());
+        CPPUNIT_ASSERT_EQUAL(u""_ustr, rNode.GetText()); // this is a new 
empty paragraph
+    }
+
+    pWrtShell->FwdPara();
+
+    {
+        SwTextNode& rNode{ 
*pWrtShell->GetCursor()->GetPoint()->GetNode().GetTextNode() };
+        // numrule from paragraph style, but not from direct formatting
+        auto pSet{ rNode.GetpSwAttrSet() };
+        CPPUNIT_ASSERT(pSet);
+        // list id was set
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_PARATR_LIST_ID, false));
+        // the numrule is set on the paragraph style, not on the paragraph
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, 
pSet->GetItemState(RES_PARATR_NUMRULE, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_PARATR_NUMRULE, true));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT,
+                             pSet->GetItemState(RES_MARGIN_FIRSTLINE, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_FIRSTLINE, true));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, false));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, 
pSet->GetItemState(RES_MARGIN_TEXTLEFT, true));
+        CPPUNIT_ASSERT_EQUAL(u"ListAndIndents"_ustr, 
rNode.GetTextColl()->GetName());
+        CPPUNIT_ASSERT_EQUAL(u"more"_ustr, rNode.GetText()); // pre-exising 
list item
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf144364)
 {
     createSwDoc();
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 000f5b4c39af..832d03d67c1e 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -5518,8 +5518,11 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
         // #i86492# - use <SwDoc::SetNumRule(..)>, because it also handles the 
<ListId>
         // Don't reset indent attributes, that would mean loss of direct
         // formatting.
-        rDoc.SetNumRule( *pCopyPam, *pNumRuleToPropagate, false, nullptr,
-                          aListIdToPropagate, true, 
/*bResetIndentAttrs=*/false );
+        // It could be that pNumRuleToPropagate is already applied via
+        // the paragraph style, in that case applying it again in mpAttrSet 
could
+        // override indents, so avoid that.
+        rDoc.SetNumRule(*pCopyPam, *pNumRuleToPropagate,
+            SwDoc::SetNumRuleMode::DontSetIfAlreadyApplied, nullptr, 
aListIdToPropagate);
     }
 
     rDoc.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index 0735380e5dc2..2a777528f4e9 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -860,11 +860,9 @@ static void lcl_ChgNumRule( SwDoc& rDoc, const SwNumRule& 
rRule )
 
 OUString SwDoc::SetNumRule( const SwPaM& rPam,
                         const SwNumRule& rRule,
-                        const bool bCreateNewList,
+                        SetNumRuleMode eMode,
                         SwRootFrame const*const pLayout,
-                        const OUString& sContinuedListId,
-                        bool bSetItem,
-                        const bool bResetIndentAttrs )
+                        const OUString& sContinuedListId)
 {
     OUString sListId;
 
@@ -902,9 +900,9 @@ OUString SwDoc::SetNumRule( const SwPaM& rPam,
         }
     }
 
-    if ( bSetItem )
+    if (!(eMode & SetNumRuleMode::DontSetItem))
     {
-        if ( bCreateNewList )
+        if (eMode & SetNumRuleMode::CreateNewList)
         {
             if ( bNewNumRuleCreated )
             {
@@ -944,7 +942,7 @@ OUString SwDoc::SetNumRule( const SwPaM& rPam,
 
             if (pRule && pRule->GetName() == pNewOrChangedNumRule->GetName())
             {
-                bSetItem = false;
+                eMode |= SetNumRuleMode::DontSetItem;
                 if ( !pTextNd->IsInList() )
                 {
                     pTextNd->AddToList();
@@ -961,21 +959,42 @@ OUString SwDoc::SetNumRule( const SwPaM& rPam,
                     if ( pCollRule && pCollRule->GetName() == 
pNewOrChangedNumRule->GetName() )
                     {
                         pTextNd->ResetAttr( RES_PARATR_NUMRULE );
-                        bSetItem = false;
+                        eMode |= SetNumRuleMode::DontSetItem;
                     }
                 }
             }
         }
     }
 
-    if ( bSetItem )
+    if (!(eMode & SetNumRuleMode::DontSetItem))
     {
-        getIDocumentContentOperations().InsertPoolItem(aPam,
-                SwNumRuleItem(pNewOrChangedNumRule->GetName()),
-                SetAttrMode::DEFAULT, pLayout);
+        if (eMode & SetNumRuleMode::DontSetIfAlreadyApplied)
+        {
+            for (SwNodeIndex i = aPam.Start()->nNode; i <= aPam.End()->nNode; 
++i)
+            {
+                if (SwTextNode const*const pNode = i.GetNode().GetTextNode())
+                {
+                    if (pNode->GetNumRule(true) != pNewOrChangedNumRule)
+                    {
+                        // only apply if it doesn't already have it - to
+                        // avoid overriding indents from style
+                        SwPaM const temp(*pNode, 0, *pNode, pNode->Len());
+                        getIDocumentContentOperations().InsertPoolItem(temp,
+                                SwNumRuleItem(pNewOrChangedNumRule->GetName()),
+                                SetAttrMode::DEFAULT, pLayout);
+                    }
+                }
+            }
+        }
+        else
+        {
+            getIDocumentContentOperations().InsertPoolItem(aPam,
+                    SwNumRuleItem(pNewOrChangedNumRule->GetName()),
+                    SetAttrMode::DEFAULT, pLayout);
+        }
     }
 
-    if ( bResetIndentAttrs
+    if ((eMode & SetNumRuleMode::ResetIndentAttrs)
          && pNewOrChangedNumRule->Get( 0 ).GetPositionAndSpaceMode() == 
SvxNumberFormat::LABEL_ALIGNMENT )
     {
         const o3tl::sorted_vector<sal_uInt16> attrs{ RES_MARGIN_FIRSTLINE, 
RES_MARGIN_TEXTLEFT, RES_MARGIN_RIGHT };
@@ -1275,7 +1294,7 @@ void SwDoc::MakeUniqueNumRules(const SwPaM & rPaM)
 
                 SetNumRule( aPam,
                             *aListStyleData.pReplaceNumRule,
-                            aListStyleData.bCreateNewList,
+                            aListStyleData.bCreateNewList ? 
SetNumRuleMode::CreateNewList : SetNumRuleMode::Default,
                             nullptr,
                             aListStyleData.sListId );
                 if ( aListStyleData.bCreateNewList )
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 6fafe1310d72..2082fa3ae4c6 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -1710,7 +1710,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 
nDigitLevel )
             
const_cast<SwTextNode*>(m_pCurTextFrame->GetTextNodeForParaProps())->SetAttrListLevel(nLvl);
 
             // start new list
-            m_pDoc->SetNumRule(m_aDelPam, aRule, true, 
m_pEditShell->GetLayout());
+            m_pDoc->SetNumRule(m_aDelPam, aRule, 
SwDoc::SetNumRuleMode::CreateNewList, m_pEditShell->GetLayout());
             m_aDelPam.DeleteMark();
 
             *m_aDelPam.GetPoint() = 
m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
diff --git a/sw/source/core/edit/ednumber.cxx b/sw/source/core/edit/ednumber.cxx
index c272aa5f8eec..65391d376b4a 100644
--- a/sw/source/core/edit/ednumber.cxx
+++ b/sw/source/core/edit/ednumber.cxx
@@ -355,7 +355,7 @@ void SwEditShell::SetIndent(short nIndent, const SwPosition 
& rPos)
 
         // change numbering rule - changed numbering rule is not applied at 
<aPaM>
         SwPaM aPaM(pos);
-        GetDoc()->SetNumRule(aPaM, aRule, false, GetLayout(), OUString(), 
false);
+        GetDoc()->SetNumRule(aPaM, aRule, SwDoc::SetNumRuleMode::DontSetItem, 
GetLayout(), OUString());
     }
 
     EndAllAction();
@@ -751,8 +751,9 @@ void SwEditShell::SetCurNumRule( const SwNumRule& rRule,
         for (SwPaM& rPaM : pCursor->GetRingContainer())
         {
             OUString sListId = GetDoc()->SetNumRule(rPaM, rRule,
-                                  bCreateNewList, GetLayout(), 
sContinuedListId,
-                                  true, bResetIndentAttrs );
+              (bCreateNewList ? SwDoc::SetNumRuleMode::CreateNewList : 
SwDoc::SetNumRuleMode::Default)
+              | (bResetIndentAttrs ? SwDoc::SetNumRuleMode::ResetIndentAttrs : 
SwDoc::SetNumRuleMode::Default),
+              GetLayout(), sContinuedListId);
 
             //tdf#87548 On creating a new list for a multi-selection only
             //create a single new list for the multi-selection, not one per 
selection
@@ -768,8 +769,9 @@ void SwEditShell::SetCurNumRule( const SwNumRule& rRule,
     else
     {
         GetDoc()->SetNumRule( *pCursor, rRule,
-                              bCreateNewList, GetLayout(), rContinuedListId,
-                              true, bResetIndentAttrs );
+              (bCreateNewList ? SwDoc::SetNumRuleMode::CreateNewList : 
SwDoc::SetNumRuleMode::Default)
+              | (bResetIndentAttrs ? SwDoc::SetNumRuleMode::ResetIndentAttrs : 
SwDoc::SetNumRuleMode::Default),
+              GetLayout(), rContinuedListId);
         GetDoc()->SetCounted( *pCursor, true, GetLayout() );
     }
     GetDoc()->GetIDocumentUndoRedo().EndUndo( SwUndoId::INSATTR, nullptr );
diff --git a/sw/source/core/undo/unnum.cxx b/sw/source/core/undo/unnum.cxx
index 1251635a3135..a0aa39f3fcb3 100644
--- a/sw/source/core/undo/unnum.cxx
+++ b/sw/source/core/undo/unnum.cxx
@@ -112,7 +112,7 @@ void SwUndoInsNum::RedoImpl(::sw::UndoRedoContext & 
rContext)
         else
         {
             // #i42921# - adapt to changed signature
-            rDoc.SetNumRule(rPam, m_aNumRule, false);
+            rDoc.SetNumRule(rPam, m_aNumRule, SwDoc::SetNumRuleMode::Default);
         }
     }
 }
@@ -131,7 +131,7 @@ void SwUndoInsNum::RepeatImpl(::sw::RepeatContext & 
rContext)
         if( m_sReplaceRule.isEmpty() )
         {
             // #i42921# - adapt to changed signature
-            rDoc.SetNumRule(rContext.GetRepeatPaM(), m_aNumRule, false);
+            rDoc.SetNumRule(rContext.GetRepeatPaM(), m_aNumRule, 
SwDoc::SetNumRuleMode::Default);
         }
     }
     else
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx 
b/sw/source/core/unocore/unocrsrhelper.cxx
index 30f6d6e6190e..deb0d443b5e5 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -905,14 +905,14 @@ void setNumberingProperty(const Any& rValue, SwPaM& rPam)
                     for ( size_t n = 0; n < aRangeArr.Count(); ++n )
                     {
                         // no start of a new list
-                        rDoc.SetNumRule( aRangeArr.SetPam( n, aPam ), aRule, 
false );
+                        rDoc.SetNumRule(aRangeArr.SetPam( n, aPam ), aRule, 
SwDoc::SetNumRuleMode::Default);
                     }
                     rDoc.GetIDocumentUndoRedo().EndUndo( SwUndoId::END, 
nullptr );
                 }
                 else
                 {
                     // no start of a new list
-                    rDoc.SetNumRule( rPam, aRule, false );
+                    rDoc.SetNumRule(rPam, aRule, 
SwDoc::SetNumRuleMode::Default);
                 }
 
             }
@@ -923,7 +923,7 @@ void setNumberingProperty(const Any& rValue, SwPaM& rPam)
                 if ( !pRule )
                     throw RuntimeException();
                 // no start of a new list
-                rDoc.SetNumRule( rPam, *pRule, false );
+                rDoc.SetNumRule(rPam, *pRule, SwDoc::SetNumRuleMode::Default);
             }
             else
             {
@@ -933,7 +933,7 @@ void setNumberingProperty(const Any& rValue, SwPaM& rPam)
                 SwNumRule* pRule = rDoc.GetOutlineNumRule();
                 if(!pRule)
                     throw RuntimeException();
-                rDoc.SetNumRule( rPam, *pRule, false );
+                rDoc.SetNumRule(rPam, *pRule, SwDoc::SetNumRuleMode::Default);
             }
         }
     }
diff --git a/sw/source/filter/basflt/fltshell.cxx 
b/sw/source/filter/basflt/fltshell.cxx
index 901614897f18..c8b7ac205890 100644
--- a/sw/source/filter/basflt/fltshell.cxx
+++ b/sw/source/filter/basflt/fltshell.cxx
@@ -538,7 +538,7 @@ void SwFltControlStack::SetAttrInDoc(const SwPosition& 
rTmpPos,
                     {
                         SwPaM aTmpPam( aTmpStart, aTmpEnd );
                         // no start of a new list
-                        m_rDoc.SetNumRule( aTmpPam, *pNumRule, false );
+                        m_rDoc.SetNumRule(aTmpPam, *pNumRule, 
SwDoc::SetNumRuleMode::Default);
 
                         aTmpStart = aTmpEnd;    // here starts the next range
                         ++aTmpStart;

Reply via email to