/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
bool SwUndoOverwrite::CanGrouping( SwDoc& rDoc, SwPosition& rPos,
sal_Unicode cIns )
{ // What is with only inserted characters?
// Only deletion of single chars can be combined. if( rPos.GetNodeIndex() != m_nStartNode || m_aInsStr.isEmpty() ||
( !m_bGroup && m_aInsStr.getLength() != 1 )) returnfalse;
// Is the node a TextNode at all?
SwTextNode * pDelTextNd = rPos.GetNode().GetTextNode(); if( !pDelTextNd ||
(pDelTextNd->GetText().getLength() != rPos.GetContentIndex() &&
rPos.GetContentIndex() != ( m_nStartContent + m_aInsStr.getLength() ))) returnfalse;
CharClass& rCC = GetAppCharClass();
// ask the char that should be inserted if (( CH_TXTATR_BREAKWORD == cIns || CH_TXTATR_INWORD == cIns ) ||
rCC.isLetterNumeric( OUString( cIns ), 0 ) !=
rCC.isLetterNumeric( m_aInsStr, m_aInsStr.getLength()-1 ) ) returnfalse;
// both 'overwrites' can be combined so 'move' the corresponding character if( !m_bInsChar )
{ if (rPos.GetContentIndex() < pDelTextNd->GetText().getLength())
{
m_aDelStr += OUStringChar( pDelTextNd->GetText()[rPos.GetContentIndex()] );
rPos.AdjustContent(+1);
} else
m_bInsChar = true;
}
// If there was not only an overwrite but also an insert, delete the surplus if( m_aInsStr.getLength() > m_aDelStr.getLength() )
{
rPtPos.AdjustContent( m_aDelStr.getLength() );
pTextNd->EraseText( rPtPos, m_aInsStr.getLength() - m_aDelStr.getLength() );
rPtPos.SetContent( m_nStartContent );
}
// since the changes were added to the vector from the end of the string/node towards // the start, we need to revert them from the start towards the end now to keep the // offset information of the undo data in sync with the changing text. // Thus we need to iterate from the end of the vector to the start for (sal_Int32 i = m_aChanges.size() - 1; i >= 0; --i)
m_aChanges[i]->SetChangeAtNode( rDoc );
const sal_Int32* pOffsets = rOffsets.getConstArray(); // where did we need less memory ? const sal_Int32* p = pOffsets; for( tools::Long n = 0; n < nOffsLen; ++n, ++p ) if( *p != ( nStart + n ))
{ // create the Offset array
pNew->oOffsets.emplace( nLen );
sal_Int32* pIdx = pNew->oOffsets->getArray();
p = pOffsets;
tools::Long nMyOff, nNewVal = nStart; for( n = 0, nMyOff = nStart; n < nOffsLen; ++p, ++n, ++nMyOff )
{ if( *p < nMyOff )
{ // something is deleted
nMyOff = *p;
*(pIdx-1) = nNewVal++;
} elseif( *p > nMyOff )
{ for( ; *p > nMyOff; ++nMyOff )
*pIdx++ = nNewVal;
--nMyOff;
--n;
--p;
} else
*pIdx++ = nNewVal++;
}
// and then we need to save the attributes/bookmarks // but this data must moved every time to the last in the chain! for (size_t i = 0; i + 1 < m_aChanges.size(); ++i) // check all changes but not the current one
{
UndoTransliterate_Data* pD = m_aChanges[i].get(); if( pD->nNdIdx == pNew->nNdIdx && pD->pHistory )
{ // same node and have a history?
pNew->pHistory = std::move(pD->pHistory); break; // more can't exist
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.