sc/qa/extras/sceditfieldobj_cell.cxx |   10 ++++------
 sc/source/ui/unoobj/cellsuno.cxx     |   15 ++++-----------
 2 files changed, 8 insertions(+), 17 deletions(-)

New commits:
commit 3b45ce6ebbeacef8a570e32d796bd042f774f69f
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sat Aug 23 12:43:43 2025 +0200
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sat Aug 23 15:01:16 2025 +0200

    Simplify a bit
    
    Move interface query inside the function
    
    Change-Id: Iefcbd9a86b021dd1bda3334777d9c1c2c4fd2986
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190094
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sc/qa/extras/sceditfieldobj_cell.cxx 
b/sc/qa/extras/sceditfieldobj_cell.cxx
index 7af883bbd9d2..321837fe62dc 100644
--- a/sc/qa/extras/sceditfieldobj_cell.cxx
+++ b/sc/qa/extras/sceditfieldobj_cell.cxx
@@ -112,8 +112,9 @@ void ScEditFieldObj_Cell::tearDown()
 
 namespace
 {
-uno::Reference<text::XTextField> getNewField(const 
uno::Reference<lang::XMultiServiceFactory>& xSM)
+uno::Reference<text::XTextField> getNewField(const 
uno::Reference<uno::XInterface>& xComponent)
 {
+    uno::Reference<lang::XMultiServiceFactory> xSM(xComponent, 
uno::UNO_QUERY_THROW);
     uno::Reference<text::XTextField> xField(
         xSM->createInstance(u"com.sun.star.text.TextField.URL"_ustr), 
uno::UNO_QUERY_THROW);
     uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW);
@@ -129,10 +130,8 @@ uno::Reference<uno::XInterface> ScEditFieldObj_Cell::init()
     // Return a field that's already in the cell.
     if (!mxField.is())
     {
-        uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, 
uno::UNO_QUERY_THROW);
-
         // Create a new URL field object, and populate it with name and URL.
-        mxField = getNewField(xSM);
+        mxField = getNewField(mxComponent);
 
         // Insert this field into a cell.
         uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, 
uno::UNO_QUERY_THROW);
@@ -151,8 +150,7 @@ uno::Reference<uno::XInterface> ScEditFieldObj_Cell::init()
 uno::Reference<text::XTextContent> ScEditFieldObj_Cell::getTextContent()
 {
     // Return a field object that's not yet inserted.
-    uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, 
uno::UNO_QUERY_THROW);
-    return uno::Reference<text::XTextContent>(getNewField(xSM), 
uno::UNO_QUERY_THROW);
+    return uno::Reference<text::XTextContent>(getNewField(mxComponent), 
uno::UNO_QUERY_THROW);
 }
 
 uno::Reference<text::XTextRange> ScEditFieldObj_Cell::getTextRange()
commit 7c46f7372348ab767accbfd50cdc0a8d4df989ad
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sat Aug 23 12:38:01 2025 +0200
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sat Aug 23 15:01:08 2025 +0200

    This code is dead
    
    If getFromUnoTunnel<SvxUnoTextRangeBase> failed, there's no
    need to test getFromUnoTunnel<ScCellTextCursor>: it is derived
    from SvxUnoTextRangeBase, and will always fail.
    
    Change-Id: I9faac80c6d58ff8d5b84cdb6ab5682ffc06f6b3a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190093
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index cb2e771f9290..e39bf98f01a7 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -5865,20 +5865,13 @@ uno::Reference<text::XTextCursor> SAL_CALL 
ScCellObj::createTextCursorByRange(
                                     const uno::Reference<text::XTextRange>& 
aTextPosition )
 {
     SolarMutexGuard aGuard;
-    rtl::Reference<SvxUnoTextCursor> pCursor = new ScCellTextCursor( *this );
 
     SvxUnoTextRangeBase* pRange = 
comphelper::getFromUnoTunnel<SvxUnoTextRangeBase>( aTextPosition );
-    if(pRange)
-        pCursor->SetSelection( pRange->GetSelection() );
-    else
-    {
-        ScCellTextCursor* pOther = 
comphelper::getFromUnoTunnel<ScCellTextCursor>( aTextPosition );
-        if(!pOther)
-            throw uno::RuntimeException();
-
-        pCursor->SetSelection( pOther->GetSelection() );
+    if (!pRange)
+        throw uno::RuntimeException();
 
-    }
+    rtl::Reference<SvxUnoTextCursor> pCursor = new ScCellTextCursor(*this);
+    pCursor->SetSelection(pRange->GetSelection());
 
     return pCursor;
 }

Reply via email to