sw/qa/core/swdoc-test.cxx | 37 ++++++++++++++++++++++++++++++++++++- sw/source/core/txtnode/txtedt.cxx | 5 +++++ 2 files changed, 41 insertions(+), 1 deletion(-)
New commits: commit 3442913accc4e44c3a1ac69a990edee15117948e Author: Caolán McNamara <caol...@redhat.com> Date: Thu Jul 19 13:50:21 2012 +0100 Related: fdo#46757 fix weird word/char count with hidden deleted text i.e. changes on, but not shown then unseen deleted text counted in word/char count Change-Id: I5725063edfbfc1f6545fe1dcea9b224dbfa3a418 diff --git a/sw/qa/core/swdoc-test.cxx b/sw/qa/core/swdoc-test.cxx index 8c06e25..f76cad3 100644 --- a/sw/qa/core/swdoc-test.cxx +++ b/sw/qa/core/swdoc-test.cxx @@ -61,6 +61,8 @@ #include "fmtftn.hxx" #include "fmtrfmrk.hxx" #include "fmtfld.hxx" +#include "redline.hxx" +#include "docary.hxx" SO2_DECL_REF(SwDocShell) SO2_IMPL_REF(SwDocShell) @@ -399,7 +401,7 @@ void SwDocTest::testSwScanner() pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len()); CPPUNIT_ASSERT_EQUAL(aDocStat.nWord, static_cast<sal_uLong>(2)); - //turn on red-lining + //turn on red-lining and show changes m_pDoc->SetRedlineMode(nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_SHOW_DELETE|nsRedlineMode_t::REDLINE_SHOW_INSERT); CPPUNIT_ASSERT_MESSAGE("redlining should be on", m_pDoc->IsRedlineOn()); CPPUNIT_ASSERT_MESSAGE("redlines should be visible", IDocumentRedlineAccess::IsShowChanges(m_pDoc->GetRedlineMode())); @@ -414,6 +416,39 @@ void SwDocTest::testSwScanner() pTxtNode->SetWordCountDirty(true); pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len()); //but word-counting the text should only count the non-deleted text CPPUNIT_ASSERT_EQUAL(aDocStat.nWord, static_cast<sal_uLong>(1)); + + pTxtNode->SetWordCountDirty(true); + + //keep red-lining on but hide changes + m_pDoc->SetRedlineMode(nsRedlineMode_t::REDLINE_ON); + CPPUNIT_ASSERT_MESSAGE("redlining should be still on", m_pDoc->IsRedlineOn()); + CPPUNIT_ASSERT_MESSAGE("redlines should be invisible", !IDocumentRedlineAccess::IsShowChanges(m_pDoc->GetRedlineMode())); + + aDocStat.Reset(); + pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len()); //but word-counting the text should only count the non-deleted text + CPPUNIT_ASSERT_EQUAL(aDocStat.nWord, static_cast<sal_uLong>(1)); + + rtl::OUString sLorem = pTxtNode->GetTxt(); + CPPUNIT_ASSERT(sLorem == "Lorem"); + + const SwRedlineTbl& rTbl = m_pDoc->GetRedlineTbl(); + + SwNodes& rNds = m_pDoc->GetNodes(); + CPPUNIT_ASSERT(rTbl.Count() == 1); + + SwNodeIndex* pNodeIdx = rTbl[0]->GetContentIdx(); + CPPUNIT_ASSERT(pNodeIdx); + + pTxtNode = rNds[ pNodeIdx->GetIndex() + 1 ]->GetTxtNode(); //first deleted txtnode + CPPUNIT_ASSERT(pTxtNode); + + rtl::OUString sIpsum = pTxtNode->GetTxt(); + CPPUNIT_ASSERT(sIpsum == " ipsum"); + + aDocStat.Reset(); + pTxtNode->CountWords(aDocStat, 0, pTxtNode->Len()); //word-counting the text should only count the non-deleted text, and this whole chunk should be ignored + CPPUNIT_ASSERT_EQUAL(aDocStat.nWord, static_cast<sal_uLong>(0)); + CPPUNIT_ASSERT_EQUAL(aDocStat.nChar, static_cast<sal_uLong>(0)); } } diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index 7da33e9..9f18fc7 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -1830,6 +1830,11 @@ void SwTxtNode::ReplaceTextOnly( xub_StrLen nPos, xub_StrLen nLen, void SwTxtNode::CountWords( SwDocStat& rStat, xub_StrLen nStt, xub_StrLen nEnd ) const { + if (IsInRedlines()) + { //not counting txtnodes used to hold deleted redline content + return; + } + sal_Bool isCountAll = ( (0 == nStt) && (GetTxt().Len() == nEnd) ); ++rStat.nAllPara; // #i93174#: count _all_ paragraphs
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits