sw/source/core/doc/docedt.cxx | 3 -- sw/source/core/edit/edlingu.cxx | 35 ++++++++-------------------- sw/source/core/unocore/unoidx.cxx | 4 +-- sw/source/core/unocore/unoobj.cxx | 10 +------- sw/source/core/unocore/unorefmk.cxx | 4 +-- sw/source/uibase/shells/translatehelper.cxx | 3 -- sw/source/uibase/uno/unotxdoc.cxx | 3 -- sw/source/uibase/uno/unotxvw.cxx | 6 +--- 8 files changed, 22 insertions(+), 46 deletions(-)
New commits: commit 640a35801612123fa503fa72e8732cfb7e75caca Author: Mike Kaganski <[email protected]> AuthorDate: Tue Dec 23 15:06:18 2025 +0100 Commit: Mike Kaganski <[email protected]> CommitDate: Tue Dec 23 17:33:36 2025 +0100 Use Normalize instead of manual check and Exchange Change-Id: I7d41257a6ec63ea76ddf3f2e6aa6da05053408f6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196167 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx index 6eca6e6ab1ca..5f6a3d45ad94 100644 --- a/sw/source/core/doc/docedt.cxx +++ b/sw/source/core/doc/docedt.cxx @@ -812,8 +812,7 @@ uno::Reference< XHyphenatedWord > SwDoc::Hyphenate( { OSL_ENSURE(this == &pPam->GetDoc(), "SwDoc::Hyphenate: strangers in the night"); - if( *pPam->GetPoint() > *pPam->GetMark() ) - pPam->Exchange(); + pPam->Normalize(); SwHyphArgs aHyphArg( pPam, rCursorPos, pPageCnt, pPageSt ); SwNodeIndex aTmpIdx( pPam->GetMark()->GetNode(), 1 ); diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx index d62404093ae0..1c0618b559ed 100644 --- a/sw/source/core/edit/edlingu.cxx +++ b/sw/source/core/edit/edlingu.cxx @@ -233,8 +233,7 @@ void SwLinguIter::Start_( SwEditShell *pShell, SwDocPositions eStart, } pCursor = m_pSh->GetCursor(); - if ( *pCursor->GetPoint() > *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(); m_oStart.emplace(*pCursor->GetPoint()); m_oEnd.emplace(*pCursor->GetMark()); @@ -319,8 +318,7 @@ uno::Any SwSpellIter::Continue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt ) { pMySh->Pop(SwCursorShell::PopMode::DeleteCurrent); pCursor = pMySh->GetCursor(); - if ( *pCursor->GetPoint() > *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(); m_oStart.emplace( *pCursor->GetPoint() ); m_oEnd.emplace( *pCursor->GetMark() ); m_oCurr.emplace( *m_oStart ); @@ -382,8 +380,7 @@ uno::Any SwConvIter::Continue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt ) { pMySh->Pop(SwCursorShell::PopMode::DeleteCurrent); pCursor = pMySh->GetCursor(); - if ( *pCursor->GetPoint() > *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(); m_oStart.emplace( *pCursor->GetPoint() ); m_oEnd.emplace( *pCursor->GetMark() ); m_oCurr.emplace( *m_oStart ); @@ -482,8 +479,7 @@ uno::Any SwHyphIter::Continue( sal_uInt16* pPageCnt, sal_uInt16* pPageSt ) { pMySh->Pop(SwCursorShell::PopMode::DeleteCurrent); pCursor = pMySh->GetCursor(); - if ( *pCursor->GetPoint() > *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(); m_oEnd.emplace( *pCursor->End() ); pCursor->SetMark(); --GetCursorCnt(); @@ -600,8 +596,7 @@ void SwEditShell::SetLinguRange( SwDocPositions eStart, SwDocPositions eEnd ) { SwPaM *pCursor = GetCursor(); MakeFindRange( eStart, eEnd, pCursor ); - if( *pCursor->GetPoint() > *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(); } void SwEditShell::SpellStart( @@ -1336,8 +1331,7 @@ bool SwSpellIter::SpellSentence(svx::SpellPortions& rPortions, bool bIsGrammarCh { pMySh->Pop(SwCursorShell::PopMode::DeleteCurrent); pCursor = pMySh->GetCursor(); - if ( *pCursor->GetPoint() > *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(); m_oStart.emplace( *pCursor->GetPoint() ); m_oEnd.emplace( *pCursor->GetMark() ); m_oCurr.emplace( *m_oStart ); @@ -1353,10 +1347,8 @@ bool SwSpellIter::SpellSentence(svx::SpellPortions& rPortions, bool bIsGrammarCh // To fill the spell portions the beginning of the sentence has to be found SwPaM *pCursor = pMySh->GetCursor(); // set the mark to the right if necessary - if ( *pCursor->GetPoint() > *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(); // the cursor has to be collapsed on the left to go to the start of the sentence - if sentence ends inside of the error - pCursor->DeleteMark(); pCursor->SetMark(); bool bStartSent = pMySh->GoStartSentence(); SpellContentPositions aDeletedRedlines = lcl_CollectDeletedRedlines(pMySh); @@ -1373,10 +1365,8 @@ bool SwSpellIter::SpellSentence(svx::SpellPortions& rPortions, bool bIsGrammarCh // save the end position of the error to continue from here SwPosition aSaveStartPos = *pCursor->End(); // determine the end of the current sentence - if ( *pCursor->GetPoint() < *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(false); // again collapse to start marking after the end of the error - pCursor->DeleteMark(); pCursor->SetMark(); pMySh->GoEndSentence(); @@ -1415,8 +1405,7 @@ bool SwSpellIter::SpellSentence(svx::SpellPortions& rPortions, bool bIsGrammarCh pMySh->GetDoc()->Spell(*pCursor, m_xSpeller, nullptr, nullptr, false, pMySh->GetLayout()) >>= xSpellRet; - if ( *pCursor->GetPoint() > *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(); m_oCurr.emplace( *pCursor->GetPoint() ); m_oCurrX.emplace( *pCursor->GetMark() ); @@ -1452,8 +1441,7 @@ bool SwSpellIter::SpellSentence(svx::SpellPortions& rPortions, bool bIsGrammarCh // go to the end of sentence as the grammar check returned it // at this time the Point is behind the grammar error // and the mark points to the sentence end as - if ( *pCursor->GetPoint() < *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(false); } // the part between the last error and the end of the sentence has to be added @@ -1562,8 +1550,7 @@ void SwSpellIter::AddPortion(uno::Reference< XSpellAlternatives > const & xAl else { SwPaM *pCursor = GetSh()->GetCursor(); - if ( *pCursor->GetPoint() > *pCursor->GetMark() ) - pCursor->Exchange(); + pCursor->Normalize(); // save the start and end positions SwPosition aStart(*pCursor->GetPoint()); SwPosition aEnd(*pCursor->GetMark()); diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx index c30f1aad145c..07b58d2030f7 100644 --- a/sw/source/core/unocore/unoidx.cxx +++ b/sw/source/core/unocore/unoidx.cxx @@ -1926,9 +1926,9 @@ void SwXDocumentIndexMark::Impl::InsertTOXMark( SwTextAttr *pNewTextAttr = nullptr; rDoc.getIDocumentContentOperations().InsertPoolItem(rPam, rMark, nInsertFlags, /*pLayout*/nullptr, &pNewTextAttr); - if (bMark && *rPam.GetPoint() > *rPam.GetMark()) + if (bMark) { - rPam.Exchange(); + rPam.Normalize(); } if (!pNewTextAttr) diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index 6921b3bba5ad..b95eddd90045 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -973,10 +973,7 @@ void SAL_CALL SwXTextCursor::collapseToStart() if (rUnoCursor.HasMark()) { - if (*rUnoCursor.GetPoint() > *rUnoCursor.GetMark()) - { - rUnoCursor.Exchange(); - } + rUnoCursor.Normalize(); rUnoCursor.DeleteMark(); } } @@ -989,10 +986,7 @@ void SAL_CALL SwXTextCursor::collapseToEnd() if (rUnoCursor.HasMark()) { - if (*rUnoCursor.GetPoint() < *rUnoCursor.GetMark()) - { - rUnoCursor.Exchange(); - } + rUnoCursor.Normalize(false); rUnoCursor.DeleteMark(); } } diff --git a/sw/source/core/unocore/unorefmk.cxx b/sw/source/core/unocore/unorefmk.cxx index 5fb2c3aead4a..39458237797d 100644 --- a/sw/source/core/unocore/unorefmk.cxx +++ b/sw/source/core/unocore/unorefmk.cxx @@ -200,9 +200,9 @@ void SwXReferenceMark::Impl::InsertRefMark(SwPaM& rPam, rDoc2.getIDocumentContentOperations().InsertPoolItem( rPam, aRefMark, nInsertFlags ); - if( bMark && *rPam.GetPoint() > *rPam.GetMark()) + if (bMark) { - rPam.Exchange(); + rPam.Normalize(); } // aRefMark was copied into the document pool; now retrieve real format... diff --git a/sw/source/uibase/shells/translatehelper.cxx b/sw/source/uibase/shells/translatehelper.cxx index fefa2fac5d14..10b2976f5b2e 100644 --- a/sw/source/uibase/shells/translatehelper.cxx +++ b/sw/source/uibase/shells/translatehelper.cxx @@ -110,8 +110,7 @@ void TranslateDocumentCancellable(SwWrtShell& rWrtSh, const TranslateAPIConfig& if (bHasSelection) { // iteration will start top to bottom - if (m_pCurrentPam->GetPoint()->nNode > m_pCurrentPam->GetMark()->nNode) - m_pCurrentPam->Exchange(); + m_pCurrentPam->Normalize(); } auto const& pNodes = rWrtSh.GetNodes(); diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index fec3025831e5..554f042eac55 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -817,8 +817,7 @@ SwUnoCursor* SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > pRange->GetPositions(*pUnoCursor); if(pUnoCursor->HasMark()) { - if(*pUnoCursor->GetPoint() < *pUnoCursor->GetMark()) - pUnoCursor->Exchange(); + pUnoCursor->Normalize(false); pUnoCursor->DeleteMark(); } } diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx index e8577548ac34..d57845269f18 100644 --- a/sw/source/uibase/uno/unotxvw.cxx +++ b/sw/source/uibase/uno/unotxvw.cxx @@ -905,8 +905,7 @@ void SwXTextViewCursor::collapseToStart() if(rSh.HasSelection()) { SwPaM* pShellCursor = rSh.GetCursor(); - if(*pShellCursor->GetPoint() > *pShellCursor->GetMark()) - pShellCursor->Exchange(); + pShellCursor->Normalize(); pShellCursor->DeleteMark(); rSh.EnterStdMode(); rSh.SetSelection(*pShellCursor); @@ -927,8 +926,7 @@ void SwXTextViewCursor::collapseToEnd() if(rSh.HasSelection()) { SwPaM* pShellCursor = rSh.GetCursor(); - if(*pShellCursor->GetPoint() < *pShellCursor->GetMark()) - pShellCursor->Exchange(); + pShellCursor->Normalize(false); pShellCursor->DeleteMark(); rSh.EnterStdMode(); rSh.SetSelection(*pShellCursor);
