summaryrefslogtreecommitdiff
path: root/sw/qa/extras/uiwriter
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-02-01 13:39:19 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2022-02-02 12:06:00 +0100
commite19044a21287b6538ae5962c5fb29b711c09e4f9 (patch)
treef481c98dd8a07b3f499473315cd38d43dc430483 /sw/qa/extras/uiwriter
parent3b79c7347d14756e072265b39081bc3866e1196d (diff)
tdf#147008 sw_fieldmarkhide: fix invalid NonTextFieldmark positions
Commit ab6176e88f78d0b3aa2490fbc7858304c2d4a437 introduced a crash in ModelToViewHelper when the positions of a NonTextFieldmark are invalid. The NonTextFieldmark must always contain 1 CH_TXT_ATR_FORMELEMENT but after SplitNode() the position is (rr) p *pFieldMark->m_pPos1 $2 = SwPosition (node 10, offset 1) (rr) p *pFieldMark->m_pPos2 $3 = SwPosition (node 9, offset 0) This is because in ContentIdxStoreImpl::SaveBkmks() there is an asymmetry where the m_pPos2 is recorded to be wrongly corrected to node 9, but if the positions were swapped so that m_pPos1 is the start position, then it will not be recorded and remain in node 10. So fix this by changing the NonTextFieldmark to insert its CH_TXT_ATR_FORMELEMENT differently. There is some very subtle code in SwTextNode::Update() that is again asymmetric and (non-obviously) prefers to move m_pPos2 and leave m_pPos1 alone (by moving it to aTmpIdxReg) in case the positions are equal. But then the fieldmark code increments "rEnd" (which is really the m_pPos1 i.e. the start after InsertString() returns), and then decrements m_pPos2. So avoid the problem by removing these 2 pointless adjustments. Then it turns a bunch of tests fail because other code assumes that m_pPos1 is the end of the NonTextFieldmark, so fix MarkManager::changeFormFieldmarkType(), ModelToViewHelper and SwHistoryNoTextFieldmark to use GetMarkStart(). Change-Id: I7c82f9a67661121662c95727e0f8f15e06d85a3a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129289 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit ea06852ee87531794f07710de496734a647a9062) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129265 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sw/qa/extras/uiwriter')
-rw-r--r--sw/qa/extras/uiwriter/uiwriter2.cxx8
1 files changed, 8 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 79aa517c66f4..65142dbd64e1 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -3600,6 +3600,14 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testCheckboxFormFieldInsertion)
pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter);
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMCHECKBOX), pFieldmark->GetFieldname());
+
+ // tdf#147008 this would crash
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->StartOfSection(false);
+ pWrtShell->SplitNode();
+ CPPUNIT_ASSERT_EQUAL(pFieldmark->GetMarkPos().nNode, pFieldmark->GetOtherMarkPos().nNode);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(pFieldmark->GetMarkPos().nContent.GetIndex() + 1),
+ pFieldmark->GetOtherMarkPos().nContent.GetIndex());
}
CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDropDownFormFieldInsertion)