summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Raykowski <raykowj@gmail.com>2022-04-19 22:02:22 -0800
committerJim Raykowski <raykowj@gmail.com>2022-04-28 04:41:47 +0200
commit4c0939f900b862ae8abe585617d51898a7c0caf0 (patch)
treef657243cc12deb11fcea0ed763f0f28ad1caeca4
parentfecc129799c1ceb733dd65d3ccf28f61555b19f2 (diff)
SwNavigator: Improve ordering of hyperlinks in text frames
This patch improves ordering of the Navigator content tree Hyperlinks members that are in text frames by placing them in the order of document layout appearance. This is done by doing a second sort using the text frame anchor position. Previous to this patch only a sort using the node index of the node that contains the hyperlink and the start position of the hyperlink in the node text are used to determine sort order. This results in hyperlink entries being placed in document model order in which hyperlinks in text frames are placed before all hyperlink entries in the regular document nodes section. This sort is still always done initially with the additional anchor position sort only being done if needed. Change-Id: I26f1a12657748a09c2cccd54e89c75ea42ee2ffe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133342 Tested-by: Jenkins Reviewed-by: Jim Raykowski <raykowj@gmail.com>
-rw-r--r--sw/source/uibase/utlui/content.cxx40
1 files changed, 40 insertions, 0 deletions
diff --git a/sw/source/uibase/utlui/content.cxx b/sw/source/uibase/utlui/content.cxx
index 5f1b0c614040..44c02ffe2447 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -804,9 +804,25 @@ void SwContentType::FillMemberList(bool* pbContentChanged)
}
// use stable sort array to list hyperlinks in document order
+ const SwNodeOffset nEndOfExtrasIndex = m_pWrtShell->GetNodes().GetEndOfExtras().GetIndex();
+ bool bHasEntryInFly = false;
std::vector<SwGetINetAttr*> aStableSortINetAttrsArray;
+
for (SwGetINetAttr& r : aArr)
+ {
aStableSortINetAttrsArray.emplace_back(&r);
+ if (!bHasEntryInFly)
+ {
+ if (nEndOfExtrasIndex >= r.rINetAttr.GetTextNode().GetIndex())
+ {
+ // Not a node of BodyText
+ // Are we in a fly?
+ if (r.rINetAttr.GetTextNode().GetFlyFormat())
+ bHasEntryInFly = true;
+ }
+ }
+ }
+
std::stable_sort(aStableSortINetAttrsArray.begin(), aStableSortINetAttrsArray.end(),
[](const SwGetINetAttr* a, const SwGetINetAttr* b){
SwPosition aSwPos(const_cast<SwTextNode&>(a->rINetAttr.GetTextNode()),
@@ -815,6 +831,30 @@ void SwContentType::FillMemberList(bool* pbContentChanged)
b->rINetAttr.GetStart());
return aSwPos < bSwPos;});
+ // When there are hyperlinks in text frames do an additional sort using the text frame
+ // anchor position to place entries in the order of document layout appearance.
+ if (bHasEntryInFly)
+ {
+ std::stable_sort(aStableSortINetAttrsArray.begin(), aStableSortINetAttrsArray.end(),
+ [nEndOfExtrasIndex](const SwGetINetAttr* a, const SwGetINetAttr* b){
+ const SwTextNode& aTextNode = a->rINetAttr.GetTextNode();
+ const SwTextNode& bTextNode = b->rINetAttr.GetTextNode();
+ SwPosition aPos(const_cast<SwTextNode&>(aTextNode), a->rINetAttr.GetStart());
+ SwPosition bPos(const_cast<SwTextNode&>(bTextNode), b->rINetAttr.GetStart());
+ // use anchor position for entries that are located in flys
+ if (nEndOfExtrasIndex >= aTextNode.GetIndex())
+ {
+ if (auto pFlyFormat = aTextNode.GetFlyFormat())
+ aPos = *pFlyFormat->GetAnchor().GetContentAnchor();
+ }
+ if (nEndOfExtrasIndex >= bTextNode.GetIndex())
+ {
+ if (auto pFlyFormat = bTextNode.GetFlyFormat())
+ bPos = *pFlyFormat->GetAnchor().GetContentAnchor();
+ }
+ return aPos < bPos;});
+ }
+
SwGetINetAttrs::size_type n = 0;
for (auto p : aStableSortINetAttrsArray)
{