sw/qa/extras/uiwriter/uiwriter2.cxx  |   36 +++++++++++++++++++++++++++++++++++
 sw/source/uibase/dochdl/swdtflvr.cxx |    7 +++++-
 2 files changed, 42 insertions(+), 1 deletion(-)

New commits:
commit 6ad9a3d74ef6eae3e645df12dedbe059acc180c4
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed Jan 26 13:44:39 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed Jan 26 18:09:53 2022 +0100

    tdf#146966 sw: fix inserting empty rows at copying multiple rows
    
    HTML expansion of the clipboard content is used to calculate the
    row number of the table on the clipboard. Skip its empty <tr></tr>
    elements here, similar to Paste As HTML in Edit->Paste Special->
    Paste Special... to avoid inserting empty rows (e.g. selecting and
    copying/moving 4 rows inserted 30 extra empty rows).
    
    Note: likely this was a regression, related to the new empty
    rows in the clipboard/expansion code.
    
    Change-Id: I58b16c7869c08cda7e2a2c21c3c03bf38446d826
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128986
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index a1fc810fafec..f730a0285d87 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -5156,6 +5156,42 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, 
testPasteTrackedTableRowInHideChangesMode)
     CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf146966)
+{
+    // load a 4-row table, select more than 1 row and copy them
+    // to check insertion of unnecessary empty rows
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf144748.fodt");
+
+    // check table row count
+    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xTables(xTextTablesSupplier->getTextTables(),
+                                                    uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
+    uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable->getRows()->getCount());
+
+    // copy table row and paste it by Paste Special->Rows Above
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Down(/*bSelect=*/false);
+    dispatchCommand(mxComponent, ".uno:SelectTable", {});
+    dispatchCommand(mxComponent, ".uno:Copy", {});
+    dispatchCommand(mxComponent, ".uno:Escape", {});
+    dispatchCommand(mxComponent, ".uno:PasteRowsBefore", {});
+
+    // This was 35 (extra empty rows)
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(8), xTable->getRows()->getCount());
+
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+    dispatchCommand(mxComponent, ".uno:Undo", {}); // FIXME Why 3 Undos?
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable->getRows()->getCount());
+
+    dispatchCommand(mxComponent, ".uno:Redo", {});
+    dispatchCommand(mxComponent, ".uno:Redo", {});
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(8), xTable->getRows()->getCount());
+    // dispatchCommand(mxComponent, ".uno:Redo", {}); // FIXME assert
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf145091)
 {
     // load a deleted table, reject them, and delete only its text and export 
to DOCX
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx 
b/sw/source/uibase/dochdl/swdtflvr.cxx
index 883ada5147b8..65fefd68804b 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -1569,8 +1569,13 @@ bool SwTransferable::Paste(SwWrtShell& rSh, 
TransferableDataHelper& rData, RndSt
             while((nIdx = aExpand.indexOf(sSearchRowOrCol, nIdx)) > -1)
             {
                 // skip rows/columns of nested tables, based on HTML 
indentation
-                if (nIdx > 2 && (aExpand[nIdx-1] != '\t' || aExpand[nIdx-2] != 
'\t' || (bShifted && aExpand[nIdx-3] != '\t')))
+                if ( nIdx > 3 && (aExpand[nIdx-1] != '\t' || aExpand[nIdx-2] 
!= '\t' ||
+                    ( bShifted && aExpand[nIdx-3] != '\t') ) &&
+                    // skip also strange hidden empty rows <tr></tr>
+                    !aExpand.match("<tr></tr>", nIdx - 4) )
+                {
                     ++nSelectedRowsOrCols;
+                }
                 ++nIdx;
             }
             // are we at the beginning of the cell?

Reply via email to