sc/inc/cellsuno.hxx | 4 ++++ sc/source/ui/unoobj/cellsuno.cxx | 23 ++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-)
New commits: commit d4fb438cf3f3375ff72209b994f040a92b5c68db Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Aug 23 17:11:14 2025 +0500 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Aug 25 13:50:53 2025 +0200 tdf#168073: generalize the fix to other XText methods ... that take XTextRange, and that should accept the cell itself Change-Id: Id9157b53521e22059825a6d86c814f334682a3c7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190109 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190163 diff --git a/sc/inc/cellsuno.hxx b/sc/inc/cellsuno.hxx index 0c70612d2301..63640be1351d 100644 --- a/sc/inc/cellsuno.hxx +++ b/sc/inc/cellsuno.hxx @@ -116,6 +116,7 @@ class ScTableRowsObj; class ScTableValidationObj; class ScCellObj; class SolarMutexGuard; +class SvxUnoTextRangeBase; namespace editeng { class SvxBorderLine; } @@ -667,6 +668,9 @@ private: virtual void SetOnePropertyValue( const SfxItemPropertyMapEntry* pEntry, const css::uno::Any& aValue ) override; + SvxUnoTextRangeBase* + getSvxUnoTextRange(const css::uno::Reference<css::text::XTextRange>& xRange); + public: static const SvxItemPropertySet* GetEditPropertySet(); static const SfxItemPropertyMap& GetCellPropertyMap(); diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index 15b1fb9314fc..3d46da6f59fc 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -5854,6 +5854,14 @@ void ScCellObj::InputEnglishString( const OUString& rText ) } } +SvxUnoTextRangeBase* ScCellObj::getSvxUnoTextRange(const uno::Reference<text::XTextRange>& xRange) +{ + SvxUnoTextRangeBase* pRange = comphelper::getFromUnoTunnel<SvxUnoTextRangeBase>(xRange); + if (!pRange && xRange.get() == this) // cell itself passed as range? + pRange = &GetUnoText(); + return pRange; +} + // XText uno::Reference<text::XTextCursor> SAL_CALL ScCellObj::createTextCursor() @@ -5867,7 +5875,7 @@ uno::Reference<text::XTextCursor> SAL_CALL ScCellObj::createTextCursorByRange( { SolarMutexGuard aGuard; - SvxUnoTextRangeBase* pRange = comphelper::getFromUnoTunnel<SvxUnoTextRangeBase>( aTextPosition ); + SvxUnoTextRangeBase* pRange = getSvxUnoTextRange(aTextPosition); if (!pRange) throw uno::RuntimeException(); @@ -5896,18 +5904,15 @@ void SAL_CALL ScCellObj::setString( const OUString& aText ) void SAL_CALL ScCellObj::insertString( const uno::Reference<text::XTextRange>& xRange, const OUString& aString, sal_Bool bAbsorb ) { - // special handling for ScCellTextCursor is no longer needed, - // SvxUnoText::insertString checks for SvxUnoTextRangeBase instead of SvxUnoTextRange - SolarMutexGuard aGuard; - GetUnoText().insertString(xRange, aString, bAbsorb); + GetUnoText().insertString(getSvxUnoTextRange(xRange), aString, bAbsorb); } void SAL_CALL ScCellObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb ) { SolarMutexGuard aGuard; - GetUnoText().insertControlCharacter(xRange, nControlCharacter, bAbsorb); + GetUnoText().insertControlCharacter(getSvxUnoTextRange(xRange), nControlCharacter, bAbsorb); } void SAL_CALL ScCellObj::insertTextContent( const uno::Reference<text::XTextRange >& xRange, @@ -5920,11 +5925,7 @@ void SAL_CALL ScCellObj::insertTextContent( const uno::Reference<text::XTextRang throw lang::IllegalArgumentException(u"Content already inserted"_ustr, getXWeak(), 1); if (ScDocShell* pDocSh = GetDocShell(); pDocSh && pCellField) { - auto* pTextRange = comphelper::getFromUnoTunnel<SvxUnoTextRangeBase>(xRange); - if (!pTextRange && xRange.get() == this) // cell itself passed as range? - pTextRange = &GetUnoText(); - - if (pTextRange) + if (auto* pTextRange = getSvxUnoTextRange(xRange)) { SvxEditSource* pEditSource = pTextRange->GetEditSource(); ESelection aSelection(pTextRange->GetSelection());