sw/inc/ndtxt.hxx | 2 + sw/source/core/doc/DocumentContentOperationsManager.cxx | 4 +- sw/source/core/doc/extinput.cxx | 26 ++++++++-------- sw/source/core/txtnode/ndtxt.cxx | 6 +++ 4 files changed, 23 insertions(+), 15 deletions(-)
New commits: commit 4978c106cfffa4be63f3281b84e3aa80f56c0278 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Sep 22 16:02:38 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Sep 23 21:40:52 2022 +0200 add a SwTextNode::ReplaceText variant that takes a SwPosition part of the process of hiding the internals of SwPosition Change-Id: I6eeac9861f3d170d89b78f71a45bf48dd8478c13 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140437 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx index ecd24ca55ba0..feaa6c4c1bc2 100644 --- a/sw/inc/ndtxt.hxx +++ b/sw/inc/ndtxt.hxx @@ -357,6 +357,8 @@ public: /// the capacity of the node void ReplaceText( const SwContentIndex& rStart, const sal_Int32 nDelLen, const OUString & rText ); + void ReplaceText( SwPosition& rStart, const sal_Int32 nDelLen, + const OUString & rText ); void ReplaceTextOnly( sal_Int32 nPos, sal_Int32 nLen, const OUString& rText, const css::uno::Sequence<sal_Int32>& rOffsets ); diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index f62616fa8fcb..d2187d8db1d6 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -4668,7 +4668,7 @@ bool DocumentContentOperationsManager::ReplaceRangeImpl( SwPaM& rPam, const OUSt } else if( nStt < nEnd || !sIns.isEmpty() ) { - pTextNd->ReplaceText( pStt->nContent, nEnd - nStt, sIns ); + pTextNd->ReplaceText( *pStt, nEnd - nStt, sIns ); } SplitNode( *pStt, false); bFirst = false; @@ -4682,7 +4682,7 @@ bool DocumentContentOperationsManager::ReplaceRangeImpl( SwPaM& rPam, const OUSt } else if( nStt < nEnd || !sIns.isEmpty() ) { - pTextNd->ReplaceText( pStt->nContent, nEnd - nStt, sIns ); + pTextNd->ReplaceText( *pStt, nEnd - nStt, sIns ); } } diff --git a/sw/source/core/doc/extinput.cxx b/sw/source/core/doc/extinput.cxx index 15fe67f21760..9bdcb1d4648d 100644 --- a/sw/source/core/doc/extinput.cxx +++ b/sw/source/core/doc/extinput.cxx @@ -53,8 +53,8 @@ SwExtTextInput::~SwExtTextInput() if( !pTNd ) return; - SwContentIndex& rIdx = GetPoint()->nContent; - sal_Int32 nSttCnt = rIdx.GetIndex(); + SwPosition& rPtPos = *GetPoint(); + sal_Int32 nSttCnt = rPtPos.GetContentIndex(); sal_Int32 nEndCnt = GetMark()->GetContentIndex(); if( nEndCnt == nSttCnt ) return; @@ -74,7 +74,7 @@ SwExtTextInput::~SwExtTextInput() // In order to get Undo/Redlining etc. working correctly, // we need to go through the Doc interface - rIdx = nSttCnt; + rPtPos.SetContent(nSttCnt); const OUString sText( pTNd->GetText().copy(nSttCnt, nEndCnt - nSttCnt)); if( m_bIsOverwriteCursor && !m_sOverwriteText.isEmpty() ) { @@ -82,13 +82,13 @@ SwExtTextInput::~SwExtTextInput() const sal_Int32 nOWLen = m_sOverwriteText.getLength(); if( nLen > nOWLen ) { - rIdx += nOWLen; - pTNd->EraseText( rIdx, nLen - nOWLen ); - rIdx = nSttCnt; - pTNd->ReplaceText( rIdx, nOWLen, m_sOverwriteText ); + rPtPos.AdjustContent(+nOWLen); + pTNd->EraseText( rPtPos, nLen - nOWLen ); + rPtPos.SetContent(nSttCnt); + pTNd->ReplaceText( rPtPos, nOWLen, m_sOverwriteText ); if( m_bInsText ) { - rIdx = nSttCnt; + rPtPos.SetContent(nSttCnt); rDoc.GetIDocumentUndoRedo().StartUndo( SwUndoId::OVERWRITE, nullptr ); rDoc.getIDocumentContentOperations().Overwrite( *this, sText.copy( 0, nOWLen ) ); rDoc.getIDocumentContentOperations().InsertString( *this, sText.copy( nOWLen ) ); @@ -97,10 +97,10 @@ SwExtTextInput::~SwExtTextInput() } else { - pTNd->ReplaceText( rIdx, nLen, m_sOverwriteText.copy( 0, nLen )); + pTNd->ReplaceText( rPtPos, nLen, m_sOverwriteText.copy( 0, nLen )); if( m_bInsText ) { - rIdx = nSttCnt; + rPtPos.SetContent(nSttCnt); rDoc.getIDocumentContentOperations().Overwrite( *this, sText ); } } @@ -116,11 +116,11 @@ SwExtTextInput::~SwExtTextInput() if( m_bInsText ) { - rIdx = nSttCnt; + rPtPos.SetContent(nSttCnt); rDoc.getIDocumentContentOperations().InsertString( *this, sText, SwInsertFlags::EMPTYEXPAND ); } - pTNd->EraseText( rIdx, nLenghtOfOldString ); + pTNd->EraseText( rPtPos, nLenghtOfOldString ); } if (!bWasIME) { @@ -142,7 +142,7 @@ SwExtTextInput::~SwExtTextInput() if (RES_CHRATR_LANGUAGE != nWhich && pTNd->GetLang( nSttCnt, nEndCnt-nSttCnt, nScriptType) != m_eInputLanguage) { SvxLanguageItem aLangItem( m_eInputLanguage, nWhich ); - rIdx = nSttCnt; + rPtPos.SetContent(nSttCnt); GetMark()->nContent = nEndCnt; rDoc.getIDocumentContentOperations().InsertPoolItem(*this, aLangItem ); } diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 73804928508c..b7e777ddb444 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -3825,6 +3825,12 @@ void SwTextNode::ReplaceText( const SwContentIndex& rStart, const sal_Int32 nDel } } +void SwTextNode::ReplaceText( SwPosition& rStart, const sal_Int32 nDelLen, + const OUString & rStr) +{ + ReplaceText(rStart.nContent, nDelLen, rStr); +} + namespace { void lcl_ResetParAttrs( SwTextNode &rTextNode ) {