sw/inc/ndindex.hxx              |    1 -
 sw/source/filter/ww8/wrtww8.cxx |   15 +++++++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

New commits:
commit dd873175affb7926befb1b8a0a881540d00160df
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Mar 25 07:47:15 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Mar 26 15:35:40 2024 +0100

    try to use more reliable mechanism in AddLinkTarget
    
    The commit that introduces this code says
        commit 89ffe6149a0e14bcde89d7981362aa1556849ab0
        Author: Tünde Tóth <tund...@gmail.com>
        Date:   Wed Sep 18 10:13:50 2019 +0200
    
        tdf#127605 DOCX export: fix internal hyperlinks to image target
    
        jumping to the paragraph anchored by the image as a workaround.
    
    But using the SwNodeIndex ring to do this only works by accident,
    there is no guarantee that the SwNodeIndex is organised in any
    way at all.
    
    Change-Id: I9f886522ddf83b6799da9dd3d1f27e4b6c44bdc0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165264
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index 775546597500..5ebc32846739 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -119,7 +119,6 @@ public:
     const SwNodes& GetNodes() const { return m_pNode->GetNodes(); }
           SwNodes& GetNodes() { return m_pNode->GetNodes(); }
 
-    const SwNodeIndex* GetNext() const { return GetNextInRing(); }
     SwNode& GetNode() const { return *m_pNode; }
 };
 
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 72ed190b4ec2..b252e4d1533d 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -118,6 +118,7 @@
 #include <iodetect.hxx>
 #include <fmtwrapinfluenceonobjpos.hxx>
 #include <officecfg/Office/Common.hxx>
+#include <fmtanchr.hxx>
 
 using namespace css;
 using namespace sw::util;
@@ -3280,8 +3281,11 @@ void MSWordExportBase::AddLinkTarget(std::u16string_view 
rURL)
     {
         OUString aName(BookmarkToWriter(aURL.subView(0, nPos)));
         if (const SwFlyFrameFormat* pFormat = m_rDoc.FindFlyByName(aName, 
SwNodeType::Grf))
-            if (const SwNodeIndex* pIdx = 
pFormat->GetContent().GetContentIdx())
-                m_aImplicitBookmarks.emplace_back(aURL, 
pIdx->GetNext()->GetIndex());
+        {
+            const SwFormatAnchor& rFormatAnchor = pFormat->GetAnchor();
+            if (SwNode* pAnchorNode = rFormatAnchor.GetAnchorNode())
+                m_aImplicitBookmarks.emplace_back(aURL, 
pAnchorNode->GetIndex());
+        }
     }
     else if( sCmp == "frame" )
     {
@@ -3294,8 +3298,11 @@ void MSWordExportBase::AddLinkTarget(std::u16string_view 
rURL)
     {
         OUString aName(BookmarkToWriter(aURL.subView(0, nPos)));
         if (const SwFlyFrameFormat* pFormat = m_rDoc.FindFlyByName(aName, 
SwNodeType::Ole))
-            if (const SwNodeIndex* pIdx = 
pFormat->GetContent().GetContentIdx())
-                m_aImplicitBookmarks.emplace_back(aURL, 
pIdx->GetNext()->GetIndex());
+        {
+            const SwFormatAnchor& rFormatAnchor = pFormat->GetAnchor();
+            if (SwNode* pAnchorNode = rFormatAnchor.GetAnchorNode())
+                m_aImplicitBookmarks.emplace_back(aURL, 
pAnchorNode->GetIndex());
+        }
     }
     else if( sCmp == "region" )
     {

Reply via email to