summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-04-24 08:22:10 +0200
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-04-24 09:37:08 +0200
commitfca9f7899843336d0ff0198a522ec8ccbb4273da (patch)
tree57651e170ad9ddc6201a6f4df3762dc67c3c926b
parent1675c3e2f14c68873e63cb725e0dd6e4b70cb3c3 (diff)
cool#8789 sc lok: classify multi-selection with 2 cells as simple distro/collabora/co-23.05
The trouble was that even if commit b13c7b31f9ce3c3a25cffd0c35e7ee6b8c2a1895 (cool#8789 sc lok: fix copy for multi-selections, 2024-04-19) made multi-selection copy work, just 2 cells in a multi-selection was classified as a complex selection at a LOK level, while 2 cells next to each other is a simple selection, which is inconsistent. (A LOK client can provide a simpler UI for simple selections.) What happens is that the multi-selection clipboard document had no selection ranges defined, so ScDocument::GetClipArea() returned early, so the numbers in the ScTransferObj ctor were left initialized, which at the end lead to a >1000 cells in ScTransferObj::isComplex(), because we were calculating uninitialized data. Fix the problem by passing a range (that covers all ranges of the multi-selection) to ScViewFunc::CopyToTransferable(), which avoids the wrong col/row start/length, so the selection is classified as simple. Also adapt testRowColumnSelections, which was just meant to check we don't crash, but now the cell under the cell cursor is returned, so the assert about the empty selection would fail. Change-Id: If98212c623fa75adb2ddf628a6e90f3eef450e59 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166574 Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r--sc/qa/unit/tiledrendering/tiledrendering.cxx10
-rw-r--r--sc/source/ui/view/viewfun3.cxx2
2 files changed, 9 insertions, 3 deletions
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index 6e47eefd5cd0..65844f2546f8 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -407,7 +407,7 @@ void ScTiledRenderingTest::testRowColumnSelections()
// When we copy this, we don't get anything useful, but we must not crash
// (used to happen)
aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8");
- CPPUNIT_ASSERT_EQUAL(OString(), aResult);
+ CPPUNIT_ASSERT_EQUAL(OString("9"), aResult);
// TODO check that we really selected what we wanted here
@@ -419,7 +419,7 @@ void ScTiledRenderingTest::testRowColumnSelections()
// When we copy this, we don't get anything useful, but we must not crash
// (used to happen)
aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8");
- CPPUNIT_ASSERT_EQUAL(OString(), aResult);
+ CPPUNIT_ASSERT_EQUAL(OString("1"), aResult);
// TODO check that we really selected what we wanted here
@@ -4154,6 +4154,12 @@ void ScTiledRenderingTest::testCopyMultiSelection()
// Make sure we get A1+A3 instead of an error:
CPPUNIT_ASSERT(xTransferable.is());
+
+ // Also make sure that just 2 cells is classified as a simple selection:
+ uno::Reference<datatransfer::XTransferable2> xTransferable2(xTransferable, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xTransferable2.is());
+ // Without the fix, the text selection was complex.
+ CPPUNIT_ASSERT(!xTransferable2->isComplex());
}
}
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 769805d5d32a..6540e8f15f6f 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -464,7 +464,7 @@ rtl::Reference<ScTransferObj> ScViewFunc::CopyToTransferable()
{
ScDocumentUniquePtr pClipDoc(new ScDocument(SCDOCMODE_CLIP));
// This takes care of the input line and calls CopyToClipMultiRange() for us.
- CopyToClip(pClipDoc.get(), /*bCut=*/false, /*bApi=*/true);
+ CopyToClip(pClipDoc.get(), aRange, /*bCut=*/false, /*bApi=*/true);
TransferableObjectDescriptor aObjDesc;
return new ScTransferObj(std::move(pClipDoc), std::move(aObjDesc));
}