Kaydet (Commit) 91a90acc authored tarafından Michael Stahl's avatar Michael Stahl

SwUndoSaveCntnt: simplify Move{From,To}UndoNds

If we always create a new text node in MoveToUndoNds, there is no need
for this silly and fragile adding of a "space" at the end, and clients
can rely on having a unique start node for their content.

Change-Id: I60937f33bac8ae2f9732eebfe6e8083b6bb2f210
üst 5f75082e
......@@ -332,22 +332,9 @@ void SwUndoSaveCntnt::MoveToUndoNds( SwPaM& rPaM, SwNodeIndex* pNodeIdx,
SwNodes & rNds = rDoc.GetUndoManager().GetUndoNodes();
SwPosition aPos( pEndNdIdx ? rNds.GetEndOfPostIts()
: rNds.GetEndOfExtras() );
aPos.nNode--;
const SwPosition* pStt = rPaM.Start(), *pEnd = rPaM.End();
if( pCpyNd || pEndNdIdx || !aPos.nNode.GetNode().GetCntntNode() ||
(!pStt->nContent.GetIndex() && (pStt->nNode != pEnd->nNode ||
(!pStt->nNode.GetNode().GetCntntNode() ||
pStt->nNode.GetNode().GetCntntNode()->Len() ==
pEnd->nContent.GetIndex() ) ) ) )
{
aPos.nNode++;
aPos.nContent = 0;
}
else
aPos.nNode.GetNode().GetCntntNode()->MakeEndIndex( &aPos.nContent );
// keep as sal_uInt16; the indices shift!
sal_uLong nTmpMvNode = aPos.nNode.GetIndex();
xub_StrLen nTmpMvCntnt = aPos.nContent.GetIndex();
......@@ -362,29 +349,6 @@ void SwUndoSaveCntnt::MoveToUndoNds( SwPaM& rPaM, SwNodeIndex* pNodeIdx,
else
{
rDoc.GetNodes().MoveRange( rPaM, aPos, rNds );
SwTxtNode* pTxtNd = aPos.nNode.GetNode().GetTxtNode();
if( pTxtNd ) // add a seperator for the attributes
{
// But since all attributes will be touched at an insert (meaning
// deleted from the array and re-added again), attributes might
// disappear (e.g. "no bold" for 10-20, "bold" for 12-15 -> when
// inserting/deleting, the "bold" will be deleted, which is not
// wanted here!)! Thus do not touch the hints but manipulate the
// string directly.
String& rStr = (String&)pTxtNd->GetTxt();
// For safety reasons better only if positioned at the end
if( rStr.Len() == aPos.nContent.GetIndex() )
{
rStr.Insert( ' ' );
++aPos.nContent;
}
else
{
pTxtNd->InsertText( rtl::OUString(' '), aPos.nContent,
IDocumentContentOperations::INS_NOHINTEXPAND );
}
}
}
if( pEndNdIdx )
*pEndNdIdx = aPos.nNode.GetIndex();
......@@ -427,15 +391,10 @@ void SwUndoSaveCntnt::MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx,
}
SwTxtNode* pTxtNd = aPaM.GetNode()->GetTxtNode();
if( !pEndNdIdx && pTxtNd ) // delete the seperator again
if (!pEndNdIdx && pTxtNd)
{
if( pEndCntIdx )
aPaM.GetPoint()->nContent.Assign( pTxtNd, *pEndCntIdx );
if( pTxtNd->GetTxt().Len() )
{
GoInCntnt( aPaM, fnMoveBackward );
pTxtNd->EraseText( aPaM.GetPoint()->nContent, 1 );
}
aPaM.SetMark();
aPaM.GetPoint()->nNode = nNodeIdx;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment