summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Raykowski <raykowj@gmail.com>2022-01-01 16:46:00 -0900
committerAdolfo Jayme Barrientos <fitojb@ubuntu.com>2022-01-11 04:53:00 +0100
commit3e224dc4e49b2a016bb7502031f002517237bea0 (patch)
treeee5410b074e0890b58847768c9432d410b8a5b1d
parent80570766400df268ed069f81f3793055962144f6 (diff)
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 <raykowj@gmail.com> (cherry picked from commit 1aa49bb9cf2b960312bf1e65ea1eee2521873a16) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128227 Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
-rw-r--r--sw/source/uibase/utlui/content.cxx37
1 files changed, 22 insertions, 15 deletions
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index 5cfa0b7bcadc..586f8c1bc615 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();
}
}