sw/qa/extras/ww8export/ww8export3.cxx | 3 ++- sw/source/filter/ww8/ww8par5.cxx | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-)
New commits: commit 2c7e4d31662add89f0fa4c7a8e007caaacadc0b7 Author: Justin Luth <[email protected]> AuthorDate: Fri Mar 11 14:55:00 2022 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Apr 1 17:11:45 2022 +0200 tdf#147861 ww8import: solve TODO: not fixed-field if equal Do not mark the field as "fixed" if the displayed string matches the internal variable. This allows changing the variable within LO and having the field update to reflect that change, which is the way that these fields are supposed to work (although in MS Word they only update manually via F9 which is why some needed to be fixed in the first place). (cherry picked from commit f5c2085e70c40370a790868d4683133a41e6599d) Change-Id: Id359cbf0b48e63bddab3e45871326988467d7ddb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132400 Tested-by: Miklos Vajna <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx index 80f0daf11f93..0ed99f7e64dc 100644 --- a/sw/qa/extras/ww8export/ww8export3.cxx +++ b/sw/qa/extras/ww8export/ww8export3.cxx @@ -104,7 +104,8 @@ DECLARE_WW8EXPORT_TEST(testTdf147861_customField, "tdf147861_customField.doc") { // These should each be specific values, not a shared DocProperty getParagraph(1, "CustomEditedTitle"); // edited - getParagraph(2, " INSERT Custom Title here"); // matches current DocProperty + // A couple of \x0\x0 at the end of the import variable thwart an equality comparison + CPPUNIT_ASSERT(getParagraph(2)->getString().startsWith(" INSERT Custom Title here")); getParagraph(3, "My Title"); // edited // Verify that these are fields, and not just plain text diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx index 76461ab6c86a..99841fe175fe 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -1650,13 +1650,30 @@ eF_ResT SwWW8ImplReader::Read_F_DocInfo( WW8FieldDesc* pF, OUString& rStr ) // In other words, Word lets the field to be out of sync with the controlling variable. // Marking as FIXEDFLD solves the automatic replacement problem, but of course prevents // Writer from making any changes, even on an F9 refresh. - // TODO: If the field already matches the DocProperty, no need to mark as fixed. // TODO: Extend LO to allow a linked field that doesn't automatically update. + IDocumentContentOperations& rIDCO(m_rDoc.getIDocumentContentOperations()); const auto pType(static_cast<SwDocInfoFieldType*>( m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::DocInfo))); const OUString sDisplayed = GetFieldResult(pF); - SwDocInfoField aField(pType, DI_CUSTOM | DI_SUB_FIXED | nReg, aDocProperty, sDisplayed); - m_rDoc.getIDocumentContentOperations().InsertPoolItem(*m_pPaM, SwFormatField(aField)); + SwDocInfoField aField(pType, DI_CUSTOM | nReg, aDocProperty); + + // If text already matches the DocProperty var, then safe to treat as refreshable field. + OUString sVariable = aField.ExpandField(/*bCache=*/false, nullptr); + if (sDisplayed.getLength() != sVariable.getLength()) + { + sal_Int32 nLen = sVariable.indexOf('\x0'); + if (nLen >= 0) + sVariable = sVariable.copy(0, nLen); + } + if (sDisplayed == sVariable) + rIDCO.InsertPoolItem(*m_pPaM, SwFormatField(aField)); + else + { + // They don't match, so use a fixed field to prevent LO from altering the contents. + SwDocInfoField aFixedField(pType, DI_CUSTOM | DI_SUB_FIXED | nReg, aDocProperty, + sDisplayed); + rIDCO.InsertPoolItem(*m_pPaM, SwFormatField(aFixedField)); + } return eF_ResT::OK; }
