sw/qa/uibase/shells/shells.cxx | 14 +++++++++++--- sw/source/uibase/shells/basesh.cxx | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-)
New commits: commit 471804e251b4e15b37a10920bd4b88b40f97b227 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Jan 5 10:35:21 2023 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Jan 5 12:53:48 2023 +0000 sw update of refmarks: fix handling of ignored refmarks As pointed out at <https://gerrit.libreoffice.org/c/core/+/145036/1#message-165c0282ace92160592c896c6867095d3558ee96>, it's not correct that UpdateFieldConents() uses a single index into both the provided fields/refmarks array and into the document's all refmarks array. We need a new index that counts the input fields/refmarks we got and which is not incremented for ignored refmarks. Extend the testcase to have 2 paragraphs in the document: the first paragraph has a refmark that is to be ignored and the second para has a refmark that is interesting to us. This makes the test fail. Then fix up UpdateFieldConents() to properly count how we iterate through all refmarks and the provided refmarks in parallel. Change-Id: I1fabf5b29beeabe9e8a126f1662ca8830e5c4e20 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145068 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index 0348965b234c..ae2c0bf2fb5c 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -534,10 +534,20 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertFieldmarkReadonly) CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmarks) { - // Given a document with a refmark: + // Given a document with two refmarks, one is not interesting the other is a citation: createSwDoc(); SwDoc* pDoc = getSwDoc(); uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue("Name", uno::Any(OUString("some other old refmark"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("some other old content"))), + }; + dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/false); + pWrtShell->SplitNode(); + pWrtShell->SttEndDoc(/*bStt=*/false); + aArgs = { comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), comphelper::makePropertyValue( "Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} old refmark"))), @@ -546,8 +556,6 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmarks) dispatchCommand(mxComponent, ".uno:InsertField", aArgs); // When updating that refmark: - SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); - pWrtShell->SttEndDoc(/*bStt=*/true); std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json( { "TypeName": { diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx index 5f69c6a495a0..bdd778270481 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -801,6 +801,7 @@ bool UpdateFieldConents(SfxRequest& rReq, SwWrtShell& rWrtSh) SwDoc* pDoc = rWrtSh.GetDoc(); pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSBOOKMARK, nullptr); rWrtSh.StartAction(); + sal_uInt16 nFieldIndex = 0; for (sal_uInt16 nRefMark = 0; nRefMark < pDoc->GetRefMarks(); ++nRefMark) { auto pRefMark = const_cast<SwFormatRefMark*>(pDoc->GetRefMark(nRefMark)); @@ -809,11 +810,11 @@ bool UpdateFieldConents(SfxRequest& rReq, SwWrtShell& rWrtSh) continue; } - if (aFields.getLength() <= nRefMark) + if (nFieldIndex >= aFields.getLength()) { continue; } - comphelper::SequenceAsHashMap aMap(aFields[nRefMark]); + comphelper::SequenceAsHashMap aMap(aFields[nFieldIndex++]); auto aName = aMap["Name"].get<OUString>(); pRefMark->GetRefName() = aName;