sw/qa/core/unocore/unocore.cxx | 27 +++++++++++++++++++++++++++ sw/source/core/unocore/unocrsrhelper.cxx | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-)
New commits: commit e41212466ef6b52c8890dcf0b071fac3fec11c9d Author: Michael Stahl <[email protected]> AuthorDate: Fri Mar 22 12:28:43 2024 +0100 Commit: Xisco Fauli <[email protected]> CommitDate: Fri Mar 22 18:05:10 2024 +0100 sw: GetSelectableFromAny() broken for SwXTextRange The function unnecessarily uses an intermediate XUnoTunnel variable to handle SwXTextRange, but the implementation of XUnoTunnel was removed. (regression from commit 635448a996714a81cb15b41ac4bb0c73cabfb74f) Change-Id: I90dd7acbd259e8ca562a534ad0bc9a5b85356553 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165162 Reviewed-by: Noel Grandin <[email protected]> Tested-by: Jenkins Reviewed-by: Michael Stahl <[email protected]> (cherry picked from commit 8f2de92b3da99346f7282e623d47912f40f92b7b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165171 Reviewed-by: Xisco Fauli <[email protected]> diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx index cb6f52d0fdbb..3d759e467000 100644 --- a/sw/qa/core/unocore/unocore.cxx +++ b/sw/qa/core/unocore/unocore.cxx @@ -77,6 +77,33 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testTdf119081) CPPUNIT_ASSERT_EQUAL(OUString("x"), pWrtShell->GetCurrentShellCursor().GetText()); } +CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, selectTextRange) +{ + createSwDoc(); + uno::Reference<text::XTextDocument> const xTD(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<text::XText> const xText(xTD->getText()); + uno::Reference<text::XTextCursor> const xCursor(xText->createTextCursor()); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(false); + xCursor->gotoEnd(true); + CPPUNIT_ASSERT_EQUAL(OUString("test"), xCursor->getString()); + uno::Reference<lang::XMultiServiceFactory> const xMSF(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<text::XTextSection> const xSection( + xMSF->createInstance("com.sun.star.text.TextSection"), uno::UNO_QUERY_THROW); + xText->insertTextContent(xCursor, xSection, true); + uno::Reference<text::XTextRange> const xAnchor(xSection->getAnchor()); + uno::Reference<view::XSelectionSupplier> const xView(xTD->getCurrentController(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("test"), xAnchor->getString()); + CPPUNIT_ASSERT(xView->select(uno::Any(xAnchor))); + uno::Reference<container::XIndexAccess> xSel; + CPPUNIT_ASSERT(xView->getSelection() >>= xSel); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSel->getCount()); + uno::Reference<text::XTextRange> xSelRange; + CPPUNIT_ASSERT(xSel->getByIndex(0) >>= xSelRange); + CPPUNIT_ASSERT_EQUAL(OUString("test"), xSelRange->getString()); +} + CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, flyAtParaAnchor) { createSwDoc(); diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index 831cffd5ac1d..de1927aafb31 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -232,7 +232,7 @@ void GetSelectableFromAny(uno::Reference<uno::XInterface> const& xIfc, return; } - uno::Reference<text::XTextRange> const xTextRange(xTunnel, UNO_QUERY); + uno::Reference<text::XTextRange> const xTextRange(xIfc, UNO_QUERY); if (xTextRange.is()) { SwUnoInternalPaM aPam(rTargetDoc);
