summaryrefslogtreecommitdiff
path: root/sw/source/uibase/shells
diff options
context:
space:
mode:
authorPranam Lashkari <lpranam@collabora.com>2023-01-07 02:39:38 +0530
committerMiklos Vajna <vmiklos@collabora.com>2023-01-09 10:18:52 +0000
commite65b27e79f177d27131479c46d089cad33df557b (patch)
treec242d708d6f1843e758944384a0b961b33218022 /sw/source/uibase/shells
parent71cd508c068e662f06b984810d68868787223ab1 (diff)
sw, UpdateFields: update in sorted order
This was using the order used by GetItemSurrogates() which can be hard to predict So it used to update field in uncertain ways Now it updates field in order of the fields in file Change-Id: I7fc39b476cae6ed6a7fb7186803d4205832d7a73 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145167 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com> (cherry picked from commit 83f5340538d8aa8c469de3fee6012e83f8b56317) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145129 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
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;