diff options
author | Mike Kaganski <mikekaganski@hotmail.com> | 2015-05-11 02:31:39 +1000 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-05-12 12:50:42 +0200 |
commit | 0ddd9f9ff45f61013ea18763eca4c68aedce6caa (patch) | |
tree | 75ea8c7f02d3672a1c8db23d3a7cfd6fe4e9a4a8 /sw/source | |
parent | e702c78843e387d83fd9c8fbd1597cbe27e3e656 (diff) |
tdf#70318: don't forget to clean up second fake paragraph
RTF insert is made into an empty paragraph. To do that, two splits
are made before the insert, but only one is reverted afterwards.
This patch removes the second.
Also fixes a memory leak from unreleased heap object
The corresponding unit test is corrected. It was incorrect
because \par doesn't begin new paragraph; it only ends paragraph.
If a RTF is ended with \par } then no newline is added to its end.
The old unit test only worked because of the bug fixed by this
patch. Correct way of inserting new paragraph in the end of a RTF
is \par \par}
Change-Id: I63d50a940d7960beb35f7d774c833ed8499acbef
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/filter/rtf/swparrtf.cxx | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx index 2730561bdfa2..987fba83fefb 100644 --- a/sw/source/filter/rtf/swparrtf.cxx +++ b/sw/source/filter/rtf/swparrtf.cxx @@ -50,7 +50,7 @@ sal_uLong SwRTFReader::Read(SwDoc& rDoc, const OUString& /*rBaseURL*/, SwPaM& rP // Step 1: XTextRange will be updated when content is inserted, so we know // the end position. const uno::Reference<text::XTextRange> xInsertPosition = SwXTextRange::CreateXTextRange(rDoc, *rPam.GetPoint(), 0); - SwNodeIndex* pSttNdIdx = new SwNodeIndex(rDoc.GetNodes()); + std::shared_ptr<SwNodeIndex> pSttNdIdx(new SwNodeIndex(rDoc.GetNodes())); const SwPosition* pPos = rPam.GetPoint(); // Step 2: Split once and remember the node that has been split. @@ -59,6 +59,8 @@ sal_uLong SwRTFReader::Read(SwDoc& rDoc, const OUString& /*rBaseURL*/, SwPaM& rP // Step 3: Split again. rDoc.getIDocumentContentOperations().SplitNode(*pPos, false); + std::shared_ptr<SwNodeIndex> pSttNdIdx2(new SwNodeIndex(rDoc.GetNodes())); + *pSttNdIdx2 = pPos->nNode.GetIndex(); // Step 4: Insert all content into the new node rPam.Move(fnMoveBackward); @@ -126,6 +128,27 @@ sal_uLong SwRTFReader::Read(SwDoc& rDoc, const OUString& /*rBaseURL*/, SwPaM& rP } } + if (pSttNdIdx2->GetIndex()) + { + // If we are in insert mode, join the split node that is after + // the new content with the last new node. Or in other words: + // Revert the second split node. + SwTxtNode* pTxtNode = pSttNdIdx2->GetNode().GetTxtNode(); + SwNodeIndex aPrevIdx(*pSttNdIdx2); + if (pTxtNode && pTxtNode->CanJoinPrev(&aPrevIdx) && pSttNdIdx2->GetIndex() - 1 == aPrevIdx.GetIndex()) + { + // If the last new node isn't empty, convert the node's text + // attributes into hints. Otherwise, set the new node's + // paragraph style at the next (empty) node. + SwTxtNode* pDelNd = aPrevIdx.GetNode().GetTxtNode(); + if (pTxtNode->GetTxt().getLength()) + pDelNd->FmtToTxtAttr(pTxtNode); + else + pTxtNode->ChgFmtColl(pDelNd->GetTxtColl()); + pTxtNode->JoinPrev(); + } + } + return ret; } |