summaryrefslogtreecommitdiff
path: root/sw/qa/uibase/shells
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2023-01-06 10:08:00 +0100
committerMiklos Vajna <vmiklos@collabora.com>2023-01-06 11:32:29 +0000
commit337416dafb66ed8f930d2d69e83fae438fc85f3c (patch)
tree5dd87bfa6c96de9a5e2c611b8cd99d690543e1d4 /sw/qa/uibase/shells
parentcfcd5aa6898654ad3b469ee23f2b27eef5e4a565 (diff)
sw: add a new .uno:UpdateTextFormField UNO command
It is possible to update all fieldsmarks (of a certion type, of a certain field command prefix), but one can't update the fieldmark under the cursor, which is needed for Zotero citation clusters. To make this more complex, insertion inside an existing fieldmark is explicitly not wanted, see commit a178a2ac6df8dc63a7ab8d4a19b90ae8a17baca4 (sw UI: fix crash on inserting a fieldmark inside a fieldmark, 2023-01-02). Fix the problem by adding a new .uno:UpdateTextFormField UNO command that can update the (innermost) fieldmark under the current cursor. The uno command is intentionally hidden from the customize dialog since it only makes sense to invoke it from a macro / API with parameters, not interactively. Change-Id: I46fc4f701a20839945d765eb13aec7362ab83788 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145135 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.cxx62
1 files changed, 62 insertions, 0 deletions
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index ae2c0bf2fb5c..a394221997cb 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -595,6 +595,68 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmarks)
CPPUNIT_ASSERT_EQUAL(OUString("new content"), pTextNode->GetText());
}
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateFieldmark)
+{
+ // Given a document with a fieldmark:
+ createSwDoc();
+ uno::Sequence<css::beans::PropertyValue> aArgs = {
+ comphelper::makePropertyValue("FieldType", uno::Any(OUString(ODF_UNHANDLED))),
+ comphelper::makePropertyValue("FieldCommand",
+ uno::Any(OUString("ADDIN ZOTERO_ITEM old command 1"))),
+ comphelper::makePropertyValue("FieldResult", uno::Any(OUString("old result 1"))),
+ };
+ dispatchCommand(mxComponent, ".uno:TextFormField", aArgs);
+
+ // When updating that fieldmark to have new field command & result:
+ SwDoc* pDoc = getSwDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->SttEndDoc(/*bStt=*/false);
+ pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
+ std::vector<beans::PropertyValue> aArgsVec = comphelper::JsonToPropertyValues(R"json(
+{
+ "FieldType": {
+ "type": "string",
+ "value": "vnd.oasis.opendocument.field.UNHANDLED"
+ },
+ "FieldCommandPrefix": {
+ "type": "string",
+ "value": "ADDIN ZOTERO_ITEM"
+ },
+ "Field": {
+ "type": "[]com.sun.star.beans.PropertyValue",
+ "value": {
+ "FieldType": {
+ "type": "string",
+ "value": "vnd.oasis.opendocument.field.UNHANDLED"
+ },
+ "FieldCommand": {
+ "type": "string",
+ "value": "ADDIN ZOTERO_ITEM new command 1"
+ },
+ "FieldResult": {
+ "type": "string",
+ "value": "new result 1"
+ }
+ }
+ }
+}
+)json");
+ aArgs = comphelper::containerToSequence(aArgsVec);
+ dispatchCommand(mxComponent, ".uno:UpdateTextFormField", aArgs);
+
+ // Then make sure that the document text is updated accordingly:
+ SwCursor* pCursor = pWrtShell->GetCursor();
+ OUString aActual = pCursor->Start()->GetNode().GetTextNode()->GetText();
+ static sal_Unicode const aForbidden[]
+ = { CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDSEP, CH_TXT_ATR_FIELDEND, 0 };
+ aActual = comphelper::string::removeAny(aActual, aForbidden);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: new result 1
+ // - Actual : old result 1
+ // i.e. the document text was not updated.
+ CPPUNIT_ASSERT_EQUAL(OUString("new result 1"), aActual);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */