sc/inc/cellsuno.hxx | 4 ++++ sc/source/ui/unoobj/cellsuno.cxx | 23 ++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-)
New commits: commit 02c9a71ea5344178b2849d153d0b1d83a681e334 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat Aug 23 17:11:14 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Aug 24 09:43:49 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 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 e39bf98f01a7..ea6e13f10984 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -5853,6 +5853,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() @@ -5866,7 +5874,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(); @@ -5895,18 +5903,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, @@ -5919,11 +5924,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());