summaryrefslogtreecommitdiff
path: root/sw/source/uibase/shells
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/uibase/shells')
-rw-r--r--sw/source/uibase/shells/basesh.cxx21
1 files changed, 19 insertions, 2 deletions
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx
index 9d2b17182daf..d6d4ac2ff8bb 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -801,10 +801,27 @@ bool UpdateFieldContents(SfxRequest& rReq, SwWrtShell& rWrtSh)
SwDoc* pDoc = rWrtSh.GetDoc();
pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSBOOKMARK, nullptr);
rWrtSh.StartAction();
+
+ std::vector<const SwFormatRefMark*> aRefMarks;
+
+ for (sal_uInt16 i = 0; i < pDoc->GetRefMarks(); ++i)
+ {
+ aRefMarks.push_back(pDoc->GetRefMark(i));
+ }
+
+ std::sort(aRefMarks.begin(), aRefMarks.end(),
+ [](const SwFormatRefMark* pMark1, const SwFormatRefMark* pMark2) -> bool {
+ const SwTextRefMark* pTextRefMark1 = pMark1->GetTextRefMark();
+ const SwTextRefMark* pTextRefMark2 = pMark2->GetTextRefMark();
+ SwPosition aPos1(pTextRefMark1->GetTextNode(), pTextRefMark1->GetStart());
+ SwPosition aPos2(pTextRefMark2->GetTextNode(), pTextRefMark2->GetStart());
+ return aPos1 < aPos2;
+ });
+
sal_uInt16 nFieldIndex = 0;
- for (sal_uInt16 nRefMark = 0; nRefMark < pDoc->GetRefMarks(); ++nRefMark)
+ for (auto& pIntermediateRefMark : aRefMarks)
{
- auto pRefMark = const_cast<SwFormatRefMark*>(pDoc->GetRefMark(nRefMark));
+ auto pRefMark = const_cast<SwFormatRefMark*>(pIntermediateRefMark);
if (!pRefMark->GetRefName().startsWith(rNamePrefix))
{
continue;