diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-01-04 08:56:04 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-01-04 08:41:53 +0000 |
commit | babba472391d26aed68d7ac31c7a918c08e65256 (patch) | |
tree | 2f99dc80a00e67dcdbd5a643207463b5f706c1ea /sw/qa/uibase/shells | |
parent | 2eab74ab78b0b2a7a9c846251e2b79f595bc0878 (diff) |
sw, UpdateFields: add new TypeName, NamePrefix and Fields parameters
Currently the .uno:InsertField command allows inserting a refmark with a
provided name & content, but existing refmarks can't be updated
similarly. This is a problem in case Zotero citations are to be modeled
with refmarks.
Another trouble is that refmarks don't have dummy characters and have to
stay inside a single paragraph, so we need to be careful to replace the
content in a way that keeps the refmark alive, a naive delete + insert
will delete the refmark as well.
Fix the problem by extending the existing .uno:UpdateFields command with
3 new optional parameters, somewhat similar to what commit
724180ec495a696c79332653cb6fb52ecfbccc29 (sw: add a new
.uno:UpdateBookmarks UNO command, 2022-12-14) did.
As usual, the provided new text is meant to be HTML, which allows
formatted content.
Change-Id: Ib0951aa1a39e1b47bcf8b47bc9d65c89e0853e96
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145033
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa/uibase/shells')
-rw-r--r-- | sw/qa/uibase/shells/shells.cxx | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index 2f89720cf570..0348965b234c 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -532,6 +532,61 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertFieldmarkReadonly) CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), nActual); } +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmarks) +{ + // Given a document with a refmark: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + comphelper::makePropertyValue( + "Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} old refmark"))), + comphelper::makePropertyValue("Content", uno::Any(OUString("old content"))), + }; + 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": { + "type": "string", + "value": "SetRef" + }, + "NamePrefix": { + "type": "string", + "value": "ZOTERO_ITEM CSL_CITATION" + }, + "Fields": { + "type": "[][]com.sun.star.beans.PropertyValue", + "value": [ + { + "Name": { + "type": "string", + "value": "ZOTERO_ITEM CSL_CITATION {} new refmark" + }, + "Content": { + "type": "string", + "value": "new content" + } + } + ] + } +} +)json"); + aArgs = comphelper::containerToSequence(aArgsVec); + dispatchCommand(mxComponent, ".uno:UpdateFields", aArgs); + + // Then make sure that the document text features the new content: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetPointNode().GetTextNode(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: new content + // - Actual : old content + // i.e. the doc content was not updated. + CPPUNIT_ASSERT_EQUAL(OUString("new content"), pTextNode->GetText()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |