sw/qa/extras/uiwriter/data/tdf163340.odt                |binary
 sw/qa/extras/uiwriter/uiwriter9.cxx                     |   30 ++++++++++++++++
 sw/source/core/doc/DocumentContentOperationsManager.cxx |    5 +-
 3 files changed, 33 insertions(+), 2 deletions(-)

New commits:
commit 9447211589ddb0557a55630a6c8f9bbffeb83bbd
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Mon Oct 7 15:14:10 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Apr 1 14:49:59 2025 +0200

    tdf#163340 replace list on paste
    
    Pasting paragraph with list should apply the source list to the target
    paragraph if the target is empty or completely selected.
    
    (cherry picked from commit 2321626477d4ff930d8bc392efa6ea84e8825171)
    
    Conflicts:
            sw/qa/extras/uiwriter/uiwriter9.cxx
    
    Change-Id: I27d462f121c03b6c5625f8c0967bc975d3ac2f88
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183584
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/uiwriter/data/tdf163340.odt 
b/sw/qa/extras/uiwriter/data/tdf163340.odt
new file mode 100644
index 000000000000..cae622e5b5f3
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf163340.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx 
b/sw/qa/extras/uiwriter/uiwriter9.cxx
index ca3943639ae6..507ee00a9078 100644
--- a/sw/qa/extras/uiwriter/uiwriter9.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter9.cxx
@@ -16,6 +16,7 @@
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
 #include <com/sun/star/text/XPageCursor.hpp>
+#include <com/sun/star/text/XParagraphCursor.hpp>
 #include <com/sun/star/view/XSelectionSupplier.hpp>
 
 #include <comphelper/propertysequence.hxx>
@@ -327,6 +328,35 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf144752)
     CPPUNIT_ASSERT_EQUAL(u"Word"_ustr, pWrtShell->GetSelText());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf163340)
+{
+    createSwDoc("tdf163340.odt");
+    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<text::XText> xText = xTextDocument->getText();
+    uno::Reference<view::XSelectionSupplier> 
xSelSupplier(xModel->getCurrentController(),
+                                                          
uno::UNO_QUERY_THROW);
+    uno::Reference<text::XParagraphCursor> 
xParaCursor(xTextDocument->getText()->createTextCursor(),
+                                                       uno::UNO_QUERY);
+
+    for (int i = 0; i < 14; i++)
+        xParaCursor->gotoNextParagraph(false);
+    xParaCursor->gotoEndOfParagraph(true);
+    xSelSupplier->select(uno::Any(xParaCursor));
+
+    CPPUNIT_ASSERT_EQUAL(u"A."_ustr, getProperty<OUString>(xParaCursor, 
u"ListLabelString"_ustr));
+    dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
+
+    xParaCursor = 
uno::Reference<text::XParagraphCursor>(xText->createTextCursor(), 
uno::UNO_QUERY);
+    for (int i = 0; i < 3; i++)
+        xParaCursor->gotoNextParagraph(false);
+    xParaCursor->gotoEndOfParagraph(true);
+    CPPUNIT_ASSERT_EQUAL(u"1."_ustr, getProperty<OUString>(xParaCursor, 
u"ListLabelString"_ustr));
+    xSelSupplier->select(uno::Any(xParaCursor));
+    dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
+    CPPUNIT_ASSERT_EQUAL(u"A."_ustr, getProperty<OUString>(xParaCursor, 
u"ListLabelString"_ustr));
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 234d73aecb05..8175a960f6cd 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -4932,7 +4932,6 @@ static void lcl_PopNumruleState(
     // #i86492# - restore also <ListId> item
     if ( lcl_MarksWholeNode(rPam) )
         return;
-
     if (aNumRuleItemHolderIfSet)
     {
         pDestTextNd->SetAttr(*aNumRuleItemHolderIfSet);
@@ -5124,9 +5123,11 @@ bool 
DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
     // - source contains at least one paragraph which is not in a list
     // or
     // - source is a table
+    // - tdf#163340 overwrite list if source has a list
+
     if ( pNumRuleToPropagate &&
          ((pDestTextNd && !pDestTextNd->GetText().getLength() &&
-         !pDestTextNd->IsInList() &&
+         (!pDestTextNd->IsInList() || 
rPam.GetPointNode().GetTextNode()->IsInList() ) &&
          !lcl_ContainsOnlyParagraphsInList(rPam)) ||
          rPam.GetBound().nNode.GetNode().GetNodeType() == SwNodeType::Table) )
     {

Reply via email to