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 d5d25b85cdebb9539b4ca723881fd38d9eb6063c Author: Oliver Specht <oliver.spe...@cib.de> AuthorDate: Tue Nov 12 11:55:25 2024 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Apr 2 08:47:37 2025 +0200 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. (cherry picked from commit 3e9658a201f60dee95bd1bd8421b18bf8905c308) Change-Id: I5aa6834d32f7c69b2eb9f8330b282c0ae6fca559 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183593 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx index 9d6b03ab6aa1..fb109e4b577e 100644 --- a/sw/inc/ndtxt.hxx +++ b/sw/inc/ndtxt.hxx @@ -840,6 +840,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 8175a960f6cd..25be8bf45f92 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); @@ -5124,11 +5126,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 ec2ad33d28c5..108994515b8d 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -4659,6 +4659,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;