sw/inc/ndtxt.hxx                                        |    1 
 sw/source/core/doc/DocumentContentOperationsManager.cxx |   24 ++++++++--------
 sw/source/core/txtnode/ndtxt.cxx                        |   11 +++++++
 3 files changed, 25 insertions(+), 11 deletions(-)

New commits:
commit 136faa8acb4fa0eed77700367d882330559cd36f
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Tue Nov 12 11:55:25 2024 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Mon Dec 2 21:09:46 2024 +0100

    tdf#163340 pasting paragraphs with lists changed again
    
    Pasting paragraph with a list into an empty or completely selected
    paragraph with lists has been changed:
    If the pasted paragraph(s) are all formatted with a list from the
    paragraph style then this list will be preferred.
    If some the pasted paragraphs including the first one are formatted
    with a hard list then these attributes will be preferred.
    If all paragraphs have a hard list or no list at all the list at
    the target position will be preferred.
    
    Change-Id: I5aa6834d32f7c69b2eb9f8330b282c0ae6fca559
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176478
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Tested-by: Jenkins
    (cherry picked from commit 3e9658a201f60dee95bd1bd8421b18bf8905c308)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177690
    Tested-by: allotropia jenkins <jenk...@allotropia.de>

diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index c77e91a89371..1a8cd3801f61 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -828,6 +828,7 @@ public:
     void RemoveFromListRLHidden();
     void RemoveFromListOrig();
     bool IsInList() const;
+    bool IsInListFromStyle() const;
 
     bool IsFirstOfNumRule(SwRootFrame const& rLayout) const;
 
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index ac781b7f9cd3..62c929f6f469 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -484,26 +484,28 @@ namespace
     }
 
     // #i86492#
-    bool lcl_ContainsOnlyParagraphsInList( const SwPaM& rPam )
+    bool lcl_ShouldKeepSourceList( const SwPaM& rPam )
     {
-        bool bRet = false;
-
         const SwTextNode* pTextNd = rPam.Start()->GetNode().GetTextNode();
         const SwTextNode* pEndTextNd = rPam.End()->GetNode().GetTextNode();
-        if ( pTextNd && pTextNd->IsInList() &&
-             pEndTextNd && pEndTextNd->IsInList() )
+        bool bRet = pTextNd->IsInListFromStyle();
+        //prefer list if it's a single paragraph with list from style
+        if (pTextNd == pEndTextNd && bRet)
+            return true;
+
+        if (pTextNd && pTextNd->IsInList() && !pTextNd->IsInListFromStyle() &&
+             pEndTextNd && pEndTextNd->IsInList() && 
!pEndTextNd->IsInListFromStyle())
         {
-            bRet = true;
+            bRet = false;
             SwNodeIndex aIdx(rPam.Start()->GetNode());
-
             do
             {
                 ++aIdx;
                 pTextNd = aIdx.GetNode().GetTextNode();
 
-                if ( !pTextNd || !pTextNd->IsInList() )
+                if (!pTextNd || !pTextNd->IsInList() || 
pTextNd->IsInListFromStyle())
                 {
-                    bRet = false;
+                    bRet = true;
                     break;
                 }
             } while (pTextNd != pEndTextNd);
@@ -5197,11 +5199,11 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
     // or
     // - source is a table
     // - tdf#163340 overwrite list if source has a list
+    // - overwrite also if all source paragraphs have a list from a style
 
     if ( pNumRuleToPropagate &&
          ((pDestTextNd && !pDestTextNd->GetText().getLength() &&
-         (!pDestTextNd->IsInList() || 
rPam.GetPointNode().GetTextNode()->IsInList() ) &&
-         !lcl_ContainsOnlyParagraphsInList(rPam)) ||
+         (!pDestTextNd->IsInList() || lcl_ShouldKeepSourceList(rPam) )) ||
          rPam.GetBound().nNode.GetNode().GetNodeType() == SwNodeType::Table) )
     {
         pNumRuleToPropagate = nullptr;
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index ab3a57e44778..92f0c8047bcb 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -4572,6 +4572,17 @@ bool SwTextNode::IsInList() const
     return GetNum() != nullptr && GetNum()->GetParent() != nullptr;
 }
 
+bool SwTextNode::IsInListFromStyle()  const
+{
+    if (IsInList())
+    {
+        const SwFormatColl* pFormatColl = GetFormatColl();
+        if (pFormatColl->GetItemState(RES_PARATR_NUMRULE, true) == 
SfxItemState::SET)
+            return true;
+    }
+    return false;
+
+}
 bool SwTextNode::IsFirstOfNumRule(SwRootFrame const& rLayout) const
 {
     bool bResult = false;

Reply via email to