summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-07-19 13:50:21 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-07-19 14:03:50 +0100
commit3442913accc4e44c3a1ac69a990edee15117948e (patch)
treee0031b758e3d3982efde0192c9e9741b9b4bf799
parent238eba337cedda17a9ed1ce7e91755c66446195a (diff)
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
-rw-r--r--sw/qa/core/swdoc-test.cxx37
-rw-r--r--sw/source/core/txtnode/txtedt.cxx5
2 files changed, 41 insertions, 1 deletions
diff --git a/sw/qa/core/swdoc-test.cxx b/sw/qa/core/swdoc-test.cxx
index 8c06e252bdc5..f76cad3d2c2f 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 7da33e915e77..9f18fc7401e0 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