sw/source/uibase/utlui/content.cxx |   37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

New commits:
commit 1aa49bb9cf2b960312bf1e65ea1eee2521873a16
Author:     Jim Raykowski <rayk...@gmail.com>
AuthorDate: Sat Jan 1 16:46:00 2022 -0900
Commit:     Jim Raykowski <rayk...@gmail.com>
CommitDate: Wed Jan 5 07:59:21 2022 +0100

    tdf#134960 tdf#146419 use sorted array to list hyperlinks in Navigator
    
    in document order
    
    The current approach of using layout position to list hyperlinks in
    document order works for single-page view but not for multiple-page or
    book view. This patch makes the list order layout independent by using
    SwPositions to sort the hyperlinks in document order.
    
    Change-Id: Ie09ac362aa0e8db813430de50c7f06f3072179f3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127856
    Tested-by: Jenkins
    Reviewed-by: Jim Raykowski <rayk...@gmail.com>

diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index 9e6c8afe47cf..11fa8afc92ab 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -186,23 +186,30 @@ namespace
     {
         SwGetINetAttrs aArr;
         pWrtShell->GetINetAttrs( aArr );
-        const SwGetINetAttrs::size_type nCount {aArr.size()};
-        for( SwGetINetAttrs::size_type n = 0; n < nCount; ++n )
+
+        // use stable sort array to list hyperlinks in document order
+        std::vector<SwGetINetAttr*> aStableSortINetAttrsArray;
+        for (SwGetINetAttr& r : aArr)
+            aStableSortINetAttrsArray.emplace_back(&r);
+        std::stable_sort(aStableSortINetAttrsArray.begin(), 
aStableSortINetAttrsArray.end(),
+                         [](const SwGetINetAttr* a, const SwGetINetAttr* b){
+            SwPosition 
aSwPos(const_cast<SwTextNode&>(a->rINetAttr.GetTextNode()),
+                              a->rINetAttr.GetStart());
+            SwPosition 
bSwPos(const_cast<SwTextNode&>(b->rINetAttr.GetTextNode()),
+                              b->rINetAttr.GetStart());
+            return aSwPos < bSwPos;});
+
+        SwGetINetAttrs::size_type n = 0;
+        for (auto p : aStableSortINetAttrsArray)
         {
-            SwGetINetAttr* p = &aArr[ n ];
-            tools::Long nYPos = 
p->rINetAttr.GetTextNode().FindLayoutRect().Top()
-                    + p->rINetAttr.GetStart();
-            std::unique_ptr<SwURLFieldContent> pCnt(new SwURLFieldContent(
-                                pCntType,
-                                p->sText,
-                                INetURLObject::decode(
-                                    p->rINetAttr.GetINetFormat().GetValue(),
-                                    
INetURLObject::DecodeMechanism::Unambiguous ),
-                                &p->rINetAttr,
-                                nYPos));
-            pMember->insert( std::move(pCnt) );
+            auto pCnt = make_unique<SwURLFieldContent>(
+                        pCntType, p->sText,
+                        
INetURLObject::decode(p->rINetAttr.GetINetFormat().GetValue(),
+                                              
INetURLObject::DecodeMechanism::Unambiguous),
+                        &p->rINetAttr, ++n);
+            pMember->insert(std::move(pCnt));
         }
-        return nCount;
+        return pMember->size();
     }
 }
 

Reply via email to