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 <matty@uef.fi> Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
This commit is contained in:
committed by
Miklos Vajna
parent
96cbf1a4c3
commit
58e5e3208a
@@ -250,44 +250,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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user