sw/inc/pam.hxx | 2 ++ sw/source/core/crsr/pam.cxx | 5 +++++ sw/source/uibase/wrtsh/wrtsh1.cxx | 3 +-- sw/source/uibase/wrtsh/wrtsh2.cxx | 5 ++--- 4 files changed, 10 insertions(+), 5 deletions(-)
New commits: commit 6b544507b01d479b991d3ba7c949cb70696a3f2e Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Aug 23 11:42:38 2022 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Aug 23 13:10:09 2022 +0200 Use more SwPosition::Adjust to keep the internal fields of SwPosition in sync. Add a new SwPosition::AdjustContent for when we need to update the context index alone Change-Id: Iad277f742a903157afdacd1d5c11b2abfa7d477c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138723 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx index 7002d07a017d..69d960c2881c 100644 --- a/sw/inc/pam.hxx +++ b/sw/inc/pam.hxx @@ -97,6 +97,8 @@ struct SAL_WARN_UNUSED SW_DLLPUBLIC SwPosition void AssignEndIndex( const SwContentNode& rNd ); /// Adjust node position, and resets content position to zero void Adjust( SwNodeOffset nDelta ); + /// Adjust content index, only valid to call this if the position points to a SwContentNode subclass + void AdjustContent( sal_Int32 nDelta ); }; SW_DLLPUBLIC std::ostream &operator <<(std::ostream& s, const SwPosition& position); diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index 290379a22a64..96a1336bd03a 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -251,6 +251,11 @@ void SwPosition::Adjust( SwNodeOffset nDelta ) nNode += nDelta; nContent.Assign(nNode.GetNode().GetContentNode(), 0); } +void SwPosition::AdjustContent( sal_Int32 nDelta ) +{ + assert(nNode.GetNode().GetContentNode() && "only valid to call this if we point to an SwContentNode"); + nContent += nDelta; +} void SwPosition::AssignStartIndex( const SwContentNode& rNd ) { nNode = rNd; diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 049259ab0abe..6606b65ff49f 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -1106,8 +1106,7 @@ void SwWrtShell::InsertContentControl(SwContentControlType eType) SwCursor* pCursor = getShellCursor(true); pCursor->DeleteMark(); const SwPosition* pAnchor = pFrameFormat->GetAnchor().GetContentAnchor(); - pCursor->GetPoint()->nContent = pAnchor->nContent; - ++pCursor->GetPoint()->nContent; + pCursor->GetPoint()->Assign( *pAnchor->GetContentNode(), pAnchor->GetContentIndex() + 1); } // Select before the anchor position. diff --git a/sw/source/uibase/wrtsh/wrtsh2.cxx b/sw/source/uibase/wrtsh/wrtsh2.cxx index b0b4c30d1dad..1995e7133c4a 100644 --- a/sw/source/uibase/wrtsh/wrtsh2.cxx +++ b/sw/source/uibase/wrtsh/wrtsh2.cxx @@ -125,9 +125,8 @@ bool SwWrtShell::InsertField2(SwField const& rField, SwPaM* pAnnotationRange) // Annotation range was passed in externally, and inserting the postit field shifted // its start/end positions right by one. Restore the original position for the range // start. This allows commenting on the placeholder character of the field. - SwContentIndex& rRangeStart = pAnnotationTextRange->Start()->nContent; - if (rRangeStart.GetIndex() > 0) - --rRangeStart; + if (pAnnotationTextRange->Start()->GetContentIndex() > 0) + pAnnotationTextRange->Start()->AdjustContent(-1); } IDocumentMarkAccess* pMarksAccess = GetDoc()->getIDocumentMarkAccess(); pMarksAccess->makeAnnotationMark( *pAnnotationTextRange, OUString() );