summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2022-01-26 13:44:39 +0100
committerLászló Németh <nemeth@numbertext.org>2022-01-27 08:15:41 +0100
commit29233e10f00af0af132849485648664aadefd456 (patch)
tree3b5ca46a7fb8e9ad753f0ecc40b2832a1b8ddd25
parent6dcda6ac592f062a68c029bfe26a47ad7160c930 (diff)
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 <nemeth@numbertext.org> (cherry picked from commit 6ad9a3d74ef6eae3e645df12dedbe059acc180c4) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128959
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx36
-rw-r--r--sw/source/uibase/dochdl/swdtflvr.cxx7
2 files changed, 42 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index fea93243bdc8..79aa517c66f4 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 ea95471b8a59..ddc47cda43e4 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -1576,8 +1576,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?