tdf#57274 - Link empty cells in paste special with paste all and link

Ignore the objects flag since ScViewFunc::PasteFromClip removes it.

Change-Id: Ica6961af920832de8cd16ecc945b0ea356fcc1b1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211628
Tested-by: Jenkins
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
This commit is contained in:
Andreas Heinisch
2026-10-03 20:10:40 +02:00
parent 3bc01f0c99
commit a56dd019a6
2 changed files with 40 additions and 1 deletions
+37
View File
@@ -2161,6 +2161,43 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testPasteAsLink)
WEIGHT_NORMAL, aFont.GetWeightMaybeAskConfig());
}
CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf57274_paste_special_link_empty_cells)
{
createScDoc();
ScDocument* pDoc = getScDoc();
// Source range A1:A3 spans several rows including an empty cell in A2
insertStringToCell(u"A1"_ustr, u"1");
insertStringToCell(u"A3"_ustr, u"3");
goToCell(u"A1:A3"_ustr);
dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
// Paste Special with paste all and link
goToCell(u"B1"_ustr);
uno::Sequence<beans::PropertyValue> aArgs = comphelper::InitPropertySequence(
{ { "Flags", uno::Any(u"A"_ustr) },
{ "FormulaCommand", uno::Any(sal_uInt16(ScPasteFunc::NONE)) },
{ "SkipEmptyCells", uno::Any(false) },
{ "Transpose", uno::Any(false) },
{ "AsLink", uno::Any(true) },
{ "MoveMode", uno::Any(sal_uInt16(InsCellCmd::INS_NONE)) } });
dispatchCommand(mxComponent, u".uno:InsertContents"_ustr, aArgs);
CPPUNIT_ASSERT_EQUAL(u"=$Sheet1.$A$1"_ustr, pDoc->GetFormula(1, 0, 0)); // B1
// Without the fix in place, this test would have failed with
// - Expected: =$Sheet1.$A$2
// - Actual :
// i.e. no reference was created for the empty source cell
CPPUNIT_ASSERT_EQUAL(u"=$Sheet1.$A$2"_ustr, pDoc->GetFormula(1, 1, 0)); // B2
CPPUNIT_ASSERT_EQUAL(0.0, pDoc->GetValue(1, 1, 0)); // B2
CPPUNIT_ASSERT_EQUAL(u"=$Sheet1.$A$3"_ustr, pDoc->GetFormula(1, 2, 0)); // B3
// The link to the previously empty cell must follow its source
insertStringToCell(u"A2"_ustr, u"2");
CPPUNIT_ASSERT_EQUAL(2.0, pDoc->GetValue(1, 1, 0)); // B2
}
CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf119659)
{
createScDoc();
+3 -1
View File
@@ -1556,7 +1556,9 @@ void ScColumn::CopyFromClip(
return;
ScDocument& rDocument = GetDoc();
if (rCxt.isAsLink() && rCxt.getInsertFlag() == InsertDeleteFlags::ALL)
// tdf#57274 - ignore objects since ScViewFunc::PasteFromClip removes the objects flag
if (rCxt.isAsLink()
&& (rCxt.getInsertFlag() | InsertDeleteFlags::OBJECTS) == InsertDeleteFlags::ALL)
{
// We also reference empty cells for "ALL"
// InsertDeleteFlags::ALL must always contain more flags when compared to "Insert contents" as