diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index dd971e36dec1..1135fbd38f69 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -911,6 +911,38 @@ CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf147122) CPPUNIT_ASSERT_EQUAL(Any(OUString("This is a test")), aRet); } +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf154803) +{ + mxComponent = loadFromDesktop("private:factory/scalc"); + + css::uno::Reference xDocScr(mxComponent, UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName( + "TestModule", + uno::Any( + OUString("Function TestExtendedMergedSelection\n" + // Merge A1:B2 cell range + " oActiveSheet = ThisComponent.CurrentController.ActiveSheet\n" + " oRange = oActiveSheet.getCellRangeByName(\"A1:B2\")\n" + " ThisComponent.getCurrentController.Select(oRange)\n" + " oActiveCell = ThisComponent.CurrentSelection\n" + " oActiveCell.Merge(True)\n" + // Select A1:B3 range and check for its implementation name + " oRange = oActiveSheet.getCellRangeByName(\"A1:B3\")\n" + " ThisComponent.getCurrentController.Select(oRange)\n" + " TestExtendedMergedSelection = ThisComponent.CurrentSelection.ImplementationName\n" + "End Function\n"))); + + Any aRet = executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.TestExtendedMergedSelection?" + "language=Basic&location=document"); + // Without the fix in place, this test would have failed with + // - Expected : ScCellRangeObj + // - Actual : ScCellObj + // i.e. the selection was interpreted as a single cell instead of a range + CPPUNIT_ASSERT_EQUAL(Any(OUString("ScCellRangeObj")), aRet); +} + CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf116127) { mxComponent = loadFromDesktop("private:factory/scalc"); diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx index 96b055250c72..bfde44272010 100644 --- a/sc/source/ui/unoobj/viewuno.cxx +++ b/sc/source/ui/unoobj/viewuno.cxx @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -873,13 +874,20 @@ uno::Any SAL_CALL ScTabViewObj::getSelection() ScMarkType eMarkType = rViewData.GetSimpleArea(aRange); if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE) ) { - // tdf#147122 - return cell object when a simple selection is merged + // tdf#154803 - check if range is entirely merged ScDocument& rDoc = pDocSh->GetDocument(); - const ScPatternAttr* pMarkPattern = rDoc.GetPattern(aRange.aStart); + const ScMergeAttr* pMergeAttr = rDoc.GetAttr(aRange.aStart, ATTR_MERGE); + SCCOL nColSpan = 1; + SCROW nRowSpan = 1; + if (pMergeAttr && pMergeAttr->IsMerged()) + { + nColSpan = pMergeAttr->GetColMerge(); + nRowSpan = pMergeAttr->GetRowMerge(); + } + // tdf#147122 - return cell object when a simple selection is entirely merged if (aRange.aStart == aRange.aEnd - || (pMarkPattern - && pMarkPattern->GetItemSet().GetItemState(ATTR_MERGE, false) - == SfxItemState::SET)) + || (aRange.aEnd.Col() - aRange.aStart.Col() == nColSpan - 1 + && aRange.aEnd.Row() - aRange.aStart.Row() == nRowSpan - 1)) pObj = new ScCellObj( pDocSh, aRange.aStart ); else pObj = new ScCellRangeObj( pDocSh, aRange );