sw/qa/core/txtnode/txtnode.cxx | 79 +++++++++++++++++++------------------- sw/source/core/txtnode/atrref.cxx | 20 ++++++--- 2 files changed, 55 insertions(+), 44 deletions(-)
New commits: commit 01134e5742f362b0dced135fd49c2213001d15eb Author: Matti Tyrväinen <ma...@uef.fi> AuthorDate: Mon Oct 16 09:23:15 2023 -0700 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Oct 20 21:07:52 2023 +0200 Revert change to Reference Mark behavior to avoid regression Hotfix for tdf#157287, unfixes tdf#81720. Setting the DontExpand flag would solve tdf#81720, but causes regression due to other code that depends on the old behavior. This patch restores the old behavior without reverting the UpdateFieldContent refactor included in 146941; testDontExpandRefmark is commented out for now. Change-Id: Ibaeacabec304473db63df9334e2fef46c6d9acc5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158059 Reviewed-by: Matti <ma...@uef.fi> Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> (cherry picked from commit 58e5e3208a4257a8d9f2e28d8e2d304677aa6980) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158164 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx index 4a4bf9901a2f..757d6c830247 100644 --- a/sw/qa/core/txtnode/txtnode.cxx +++ b/sw/qa/core/txtnode/txtnode.cxx @@ -247,44 +247,47 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testSplitNodeSuperscriptCopy) CPPUNIT_ASSERT(!aSet.HasItem(RES_CHRATR_ESCAPEMENT)); } -CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testDontExpandRefmark) -{ - // Given a document with a refmark: - createSwDoc(); - - uno::Sequence<css::beans::PropertyValue> aArgs = { - comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), - comphelper::makePropertyValue( - "Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} RNDpyJknp173F"))), - comphelper::makePropertyValue("Content", uno::Any(OUString("foo"))), - }; - dispatchCommand(mxComponent, ".uno:InsertField", aArgs); - - SwDoc* pDoc = getSwDoc(); - SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); - SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint(); - SwTextNode* pTextNode = rCursor.GetNode().GetTextNode(); - std::vector<SwTextAttr*> aAttrs - = pTextNode->GetTextAttrsAt(rCursor.GetContentIndex(), RES_TXTATR_REFMARK); - - auto& rRefmark = const_cast<SwFormatRefMark&>(aAttrs[0]->GetRefMark()); - auto pTextRefMark = const_cast<SwTextRefMark*>(rRefmark.GetTextRefMark()); - - // When typing after the refmark... - pWrtShell->SttEndDoc(/*bStt=*/true); - pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 3, /*bBasicCall=*/false); - pWrtShell->Insert(" bar"); - - // and skipping back to insert a comma after the refmark - pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 4, /*bBasicCall=*/false); - pWrtShell->Insert(","); - - // Without the accompanying fix in place, this test would have failed with: - // - Expected: 3 - // - Actual : 4 - // i.e. the reference mark expanded - CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(*pTextRefMark->End())); -} +/* FIXME: behavior change reverted due to regression; + * see sw/source/core/txtnode/atrref.cxx + *CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testDontExpandRefmark) + *{ + * // Given a document with a refmark: + * createSwDoc(); + * + * uno::Sequence<css::beans::PropertyValue> aArgs = { + * comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))), + * comphelper::makePropertyValue( + * "Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} RNDpyJknp173F"))), + * comphelper::makePropertyValue("Content", uno::Any(OUString("foo"))), + * }; + * dispatchCommand(mxComponent, ".uno:InsertField", aArgs); + * + * SwDoc* pDoc = getSwDoc(); + * SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + * SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint(); + * SwTextNode* pTextNode = rCursor.GetNode().GetTextNode(); + * std::vector<SwTextAttr*> aAttrs + * = pTextNode->GetTextAttrsAt(rCursor.GetContentIndex(), RES_TXTATR_REFMARK); + * + * auto& rRefmark = const_cast<SwFormatRefMark&>(aAttrs[0]->GetRefMark()); + * auto pTextRefMark = const_cast<SwTextRefMark*>(rRefmark.GetTextRefMark()); + * + * // When typing after the refmark... + * pWrtShell->SttEndDoc(true); + * pWrtShell->Right(SwCursorSkipMode::Chars, false, 3, false); + * pWrtShell->Insert(" bar"); + * + * // and skipping back to insert a comma after the refmark + * pWrtShell->Left(SwCursorSkipMode::Chars, false, 4, false); + * pWrtShell->Insert(","); + * + * // Without the accompanying fix in place, this test would have failed with: + * // - Expected: 3 + * // - Actual : 4 + * // i.e. the reference mark expanded + * CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(*pTextRefMark->End())); + *} + */ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testInsertDropDownContentControlTwice) { diff --git a/sw/source/core/txtnode/atrref.cxx b/sw/source/core/txtnode/atrref.cxx index ffb4509aee70..40848bdaf51b 100644 --- a/sw/source/core/txtnode/atrref.cxx +++ b/sw/source/core/txtnode/atrref.cxx @@ -121,8 +121,12 @@ SwTextRefMark::SwTextRefMark( SwFormatRefMark& rAttr, } SetDontMoveAttr( true ); SetOverlapAllowedAttr( true ); - SetDontExpand( true ); // like hyperlinks, reference markers shouldn't expand - SetLockExpandFlag( true ); // protect the flag + /* FIXME: Setting the DontExpand flag would solve tdf#81720, + * but old behavior was restored due to regressions; see tdf#157287. + * After applying a proper fix, remember to restore testDontExpandRefmark! + *SetDontExpand( true ); // like hyperlinks, reference markers shouldn't expand + *SetLockExpandFlag( true ); // protect the flag + */ } SwTextRefMark::~SwTextRefMark() @@ -169,8 +173,10 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, SwWrtShell& rWrtSh, OUString const SwTextNode& rTextNode = this->GetTextNode(); SwPaM aMarkers(SwPosition(rTextNode, *this->End())); IDocumentContentOperations& rIDCO = pDoc->getIDocumentContentOperations(); - this->SetLockExpandFlag(false); - this->SetDontExpand(false); + /* FIXME: see above re: expanding behavior + *this->SetLockExpandFlag(false); + *this->SetDontExpand(false); + */ if (rIDCO.InsertString(aMarkers, "XY")) { SwPaM aPasteEnd(SwPosition(rTextNode, *this->End())); @@ -200,8 +206,10 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, SwWrtShell& rWrtSh, OUString rIDCO.DeleteAndJoin(aEndMarker); } // Restore flags. - this->SetDontExpand(true); - this->SetLockExpandFlag(true); + /* FIXME: see above re: expanding behavior + *this->SetDontExpand(true); + *this->SetLockExpandFlag(true); + */ }