sc/qa/extras/sceditfieldobj_cell.cxx |    4 +---
 sc/source/ui/unoobj/cellsuno.cxx     |   13 ++++++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

New commits:
commit 1e040b72222012f9a5f1e47d19aaf0c0369e08ad
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Aug 23 12:05:12 2025 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Aug 23 20:54:48 2025 +0200

    tdf#168073: check if xRange is this
    
    And use its own XText implementation object as the range. Also relax
    the call to getFromUnoTunnel, to request SvxUnoTextRangeBase that is
    actually wanted, not arbitrarily chosen ScCellTextCursor. This makes
    this optimized code to also handle ranges returned from ScCellObj's
    own getStart() / getEnd().
    
    Change-Id: I4f500b32790f2844fdd7f54818b79b8a29525475
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190085
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit a8ce5af575ea5e05eb7c349d50b4eb08cab983ff)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190097

diff --git a/sc/qa/extras/sceditfieldobj_cell.cxx 
b/sc/qa/extras/sceditfieldobj_cell.cxx
index 4c13bdc4db8d..7af883bbd9d2 100644
--- a/sc/qa/extras/sceditfieldobj_cell.cxx
+++ b/sc/qa/extras/sceditfieldobj_cell.cxx
@@ -142,10 +142,8 @@ uno::Reference<uno::XInterface> ScEditFieldObj_Cell::init()
         uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0);
         uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW);
 
-        uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
-        uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW);
         uno::Reference<text::XTextContent> xContent(mxField, 
uno::UNO_QUERY_THROW);
-        xText->insertTextContent(xRange, xContent, false);
+        xText->insertTextContent(xText, xContent, false);
     }
     return mxField;
 }
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index d5a92d43dc5a..1f474688a098 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -5922,13 +5922,16 @@ void SAL_CALL ScCellObj::insertTextContent( const 
uno::Reference<text::XTextRang
                                                 sal_Bool bAbsorb )
 {
     SolarMutexGuard aGuard;
-    ScDocShell* pDocSh = GetDocShell();
-    if ( pDocSh && xContent.is() )
+    ScEditFieldObj* pCellField = dynamic_cast<ScEditFieldObj*>(xContent.get());
+    if (pCellField && pCellField->IsInserted())
+        throw lang::IllegalArgumentException(u"Content already inserted"_ustr, 
getXWeak(), 1);
+    if (ScDocShell* pDocSh = GetDocShell(); pDocSh && pCellField)
     {
-        ScEditFieldObj* pCellField = 
dynamic_cast<ScEditFieldObj*>(xContent.get());
-        SvxUnoTextRangeBase* pTextRange = 
comphelper::getFromUnoTunnel<ScCellTextCursor>( xRange );
+        auto* pTextRange = 
comphelper::getFromUnoTunnel<SvxUnoTextRangeBase>(xRange);
+        if (!pTextRange && xRange.get() == this) // cell itself passed as 
range?
+            pTextRange = &GetUnoText();
 
-        if ( pCellField && !pCellField->IsInserted() && pTextRange )
+        if (pTextRange)
         {
             SvxEditSource* pEditSource = pTextRange->GetEditSource();
             ESelection aSelection(pTextRange->GetSelection());

Reply via email to