sw/qa/core/unocore/unocore.cxx           |   27 +++++++++++++++++++++++++++
 sw/source/core/unocore/unocrsrhelper.cxx |    2 +-
 2 files changed, 28 insertions(+), 1 deletion(-)

New commits:
commit 9b4c239b51244dfb28a6822e2046c72e8f937227
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Mar 22 12:28:43 2024 +0100
Commit:     Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
CommitDate: Fri Mar 22 19:48:03 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 <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 8f2de92b3da99346f7282e623d47912f40f92b7b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165180
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>

diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index 381fe0dab3e2..3e52b12a363c 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -78,6 +78,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 70a724814cc6..30f6d6e6190e 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -225,7 +225,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);

Reply via email to