sw/source/uibase/shells/textfld.cxx  |    3 +--
 sw/source/uibase/shells/textsh1.cxx  |    4 ++--
 sw/source/uibase/uiview/viewling.cxx |   11 ++++++-----
 sw/source/uibase/uno/unotxdoc.cxx    |    2 +-
 sw/source/uibase/wrtsh/delete.cxx    |    3 +--
 5 files changed, 11 insertions(+), 12 deletions(-)

New commits:
commit 0925dc81415276932aef66107b2d924b22c02d1e
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Aug 23 13:57:46 2022 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Tue Aug 23 15:19:43 2022 +0200

    Use more SwPosition::Adjust
    
    to keep the internal fields of SwPosition in sync.
    
    Change-Id: I9a9889a819a3998aa4ff2188a2dc3e0cb2ec6888
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138727
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index fb1f00490391..d06acdcfb730 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -957,8 +957,7 @@ void SwTextShell::StateField( SfxItemSet &rSet )
                 if ((!pFieldBM || pFieldBM->GetFieldname() != ODF_FORMTEXT)
                     && aCursorPos.GetContentIndex() > 0)
                 {
-                    SwPosition aPos(aCursorPos);
-                    --aPos.nContent;
+                    SwPosition aPos(*aCursorPos.GetContentNode(), 
aCursorPos.GetContentIndex() - 1);
                     pFieldBM = 
GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
                 }
                 if (pFieldBM && pFieldBM->GetFieldname() == ODF_FORMTEXT &&
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index d5aff9eaa278..647ef76ade64 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1453,7 +1453,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
         sw::mark::IFieldmark* pFieldBM = 
GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
         if ( !pFieldBM )
         {
-            --aPos.nContent;
+            aPos.AdjustContent(-1);
             pFieldBM = 
GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
         }
 
@@ -2198,7 +2198,7 @@ void SwTextShell::GetState( SfxItemSet &rSet )
                 sw::mark::IFieldmark* pFieldBM = 
GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
                 if ( !pFieldBM && aPos.GetContentIndex() > 0)
                 {
-                    --aPos.nContent;
+                    aPos.AdjustContent(-1);
                     pFieldBM = 
GetShell().getIDocumentMarkAccess()->getFieldmarkFor(aPos);
                 }
                 if ( pFieldBM && (pFieldBM->GetFieldname() == ODF_FORMDROPDOWN 
|| pFieldBM->GetFieldname() == ODF_FORMDATE) )
diff --git a/sw/source/uibase/uiview/viewling.cxx 
b/sw/source/uibase/uiview/viewling.cxx
index c98e9056bfc1..45b1851ad3c5 100644
--- a/sw/source/uibase/uiview/viewling.cxx
+++ b/sw/source/uibase/uiview/viewling.cxx
@@ -186,10 +186,11 @@ void SwView::ExecLingu(SfxRequest &rReq)
                                 // check for unexpected error case
                                 OSL_ENSURE(pTextNode && 
pTextNode->GetText().getLength() >= nPointIndex,
                                     "text missing: corrupted node?" );
-                                if (!pTextNode || 
pTextNode->GetText().getLength() < nPointIndex)
-                                    nPointIndex = 0;
                                 // restore cursor to its original position
-                                
m_pWrtShell->GetCursor()->GetPoint()->nContent.Assign( pTextNode, nPointIndex );
+                                if (!pTextNode || 
pTextNode->GetText().getLength() < nPointIndex)
+                                    
m_pWrtShell->GetCursor()->GetPoint()->Assign( aPointNodeIndex );
+                                else
+                                    
m_pWrtShell->GetCursor()->GetPoint()->Assign( *pTextNode, nPointIndex );
                             }
 
                             // enable all, restore view and cursor position
@@ -511,8 +512,8 @@ void SwView::InsertThesaurusSynonym( const OUString 
&rSynonmText, const OUString
 
         // adjust existing selection
         SwPaM *pCursor = m_pWrtShell->GetCursor();
-        pCursor->GetPoint()->nContent -= nRight;
-        pCursor->GetMark()->nContent += nLeft;
+        pCursor->GetPoint()->AdjustContent(-nRight);
+        pCursor->GetMark()->AdjustContent(nLeft);
     }
 
     m_pWrtShell->Insert( rSynonmText );
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index d5a685c87349..4c67a45cdcf8 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3332,7 +3332,7 @@ void SwXTextDocument::executeFromFieldEvent(const 
StringMap& aArguments)
     sw::mark::IFieldmark* pFieldBM = 
m_pDocShell->GetWrtShell()->getIDocumentMarkAccess()->getFieldmarkFor(aPos);
     if ( !pFieldBM )
     {
-        --aPos.nContent;
+        aPos.AdjustContent(-1);
         pFieldBM = 
m_pDocShell->GetWrtShell()->getIDocumentMarkAccess()->getFieldmarkFor(aPos);
     }
     if (pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN)
diff --git a/sw/source/uibase/wrtsh/delete.cxx 
b/sw/source/uibase/wrtsh/delete.cxx
index 12a2f35b583a..4351f6f6acbb 100644
--- a/sw/source/uibase/wrtsh/delete.cxx
+++ b/sw/source/uibase/wrtsh/delete.cxx
@@ -242,8 +242,7 @@ bool SwWrtShell::DelLeft()
     {
         // If we are just to the right to a fieldmark, then remove it 
completely
         const SwPosition* pCurPos = GetCursor()->GetPoint();
-        SwPosition aPrevChar(*pCurPos);
-        --aPrevChar.nContent;
+        SwPosition aPrevChar(*pCurPos->GetContentNode(), 
pCurPos->GetContentIndex() - 1);
         sw::mark::IFieldmark* pFm = 
getIDocumentMarkAccess()->getFieldmarkAt(aPrevChar);
         if (pFm && pFm->GetMarkEnd() == *pCurPos)
         {

Reply via email to