22#include <libxml/xmlwriter.h>
26#include <osl/diagnose.h>
27#include <rtl/ustrbuf.hxx>
32#include <UndoManager.hxx>
62 if (pAnchor->
GetAnchorId() == RndStdIds::FLY_AT_CHAR)
65 if( pAnchorNode && nMovedIndex == pAnchorNode->
GetIndex() )
78 for (
size_t i = 0;
i < rRedlineSaveData.
size(); ++
i)
80 auto const& rRedline(rRedlineSaveData[
i]);
85 && rRedline.GetType() == RedlineType::Delete)
87 nEndOfRedline = rRedline.m_nEndNode;
88 o_rpFirstMergedDeletedTextNode = rDoc.
GetNodes()[rRedline.m_nSttNode]->GetTextNode();
95 assert(o_rpFirstMergedDeletedTextNode);
123 SwTextNode * pFirstMergedDeletedTextNode(
nullptr);
125 rRedlineSaveData, pFirstMergedDeletedTextNode);
129 std::vector<SwTextFrame*> frames;
133 if (pFrame->getRootFrame()->HasMergedParas())
135 assert(pFrame->GetMergedPara());
136 assert(pFrame->GetMergedPara()->pFirstNode == pFirstMergedDeletedTextNode);
137 assert(pNextNode->
GetIndex() <= pFrame->GetMergedPara()->pLastNode->GetIndex());
138 frames.push_back(pFrame);
146 pFrame->RegisterToNode(*pNextNode,
true);
179 bool bCalledByTableCpy )
189 m_bJoinNext( false ),
190 m_bTableDelLastNd( false ),
192 m_bDelFullPara( bFullPara ),
193 m_bResetPgDesc( false ),
194 m_bResetPgBrk( false ),
195 m_bFromTableCopy( bCalledByTableCpy )
196 , m_DeleteFlags(flags)
217 auto [pStt, pEnd] = rPam.
StartEnd();
222 OSL_ENSURE( rPam.
HasMark(),
"PaM without Mark" );
250 SwTextNode *pSttTextNd =
nullptr, *pEndTextNd =
nullptr;
263 bool bMoveNds = *pStt != *pEnd
266 if( pSttTextNd && pEndTextNd && pSttTextNd != pEndTextNd )
277 if( pEndTextNd->HasSwAttrSet() )
280 if( SfxItemState::SET == pEndTextNd->GetpSwAttrSet()->GetItemState(
283 if( pEndTextNd->HasSwAttrSet() &&
284 SfxItemState::SET == pEndTextNd->GetpSwAttrSet()->GetItemState(
292 if( pEnd == rPam.
GetPoint() && ( !bFullPara || pSttTextNd || pEndTextNd ) )
295 if( !pSttTextNd && !pEndTextNd )
309 if( !bFullPara && !pEndTextNd &&
323 ( (pTmpNd = rDocNds[ aRg.
aEnd.
GetIndex()+1 ])->IsEndNode() &&
353 ( (pTmpNd = rDocNds[ aRg.
aStart.
GetIndex()-1 ])->IsSectionNode() &&
381 else if (pSttTextNd && (pEndTextNd || pSttTextNd->
GetText().getLength()))
391 if( pSttTextNd && pEndTextNd )
421 if( !pSttTextNd && !pEndTextNd )
451 0, pSttTextNd->
GetText().getLength(),
true );
456 sal_Int32 nLen = (bOneNode
458 : pSttTextNd->
GetText().getLength())
469 bool emptied( !
m_aSttStr->isEmpty() && !pSttTextNd->
Len() );
470 if (!bOneNode || emptied)
473 ? pSttTextNd->CreateUndoForDelete()
474 : pSttTextNd->CreateUndo();
491 pEndTextNd->
GetText().getLength(),
true );
504 bool emptied = !
m_aEndStr->isEmpty() && !pEndTextNd->
Len();
507 ? pEndTextNd->CreateUndoForDelete()
508 : pEndTextNd->CreateUndo();
528 auto [pStt, pEnd] = rDelPam.
StartEnd();
530 if( pStt->GetNode() != pEnd->GetNode() ||
531 pStt->GetContentIndex()+1 != pEnd->GetContentIndex() ||
552 if( !pDelTextNd )
return false;
572 const bool bSaved =
FillSaveData( rDelPam, aTmpSav,
false );
616 for ( sal_uInt16
n = 0;
n < rHistory.
Count();
n++)
618 OUString aDescr = rHistory[
n]->GetDescription();
620 if (!aDescr.isEmpty())
660static OUString
lcl_DenotedPortion(std::u16string_view rStr, sal_Int32 nStart, sal_Int32 nEnd,
bool bQuoted)
664 auto nCount = nEnd - nStart;
695 assert(!
"unexpected special character");
700 aResult = aRewriter.
Apply(aResult);
704 aResult =
SwResId(STR_START_QUOTE) +
705 rStr.substr(nStart,
nCount) +
709 aResult = rStr.substr(nStart,
nCount);
717 OUStringBuffer aResult;
722 sal_Int32 nStart = 0;
725 for(
size_t i = 0;
i <
aStr.size();
i++)
729 if (cLast !=
aStr[
i])
755 return aResult.makeStringAndClear();
772 OUString sTmp = aRewriter.
Apply(
SwResId(STR_TABLE_NAME));
789 std::optional<OUString> aTmpStr;
822 for(
auto pSpz: rSpzs)
824 pAnchor = &pSpz->GetAnchor();
825 if (pAnchor->
GetAnchorId() == RndStdIds::FLY_AT_PARA)
828 if( pAnchorNode && nOldIdx == pAnchorNode->
GetIndex() )
832 pSpz->SetFormatAttr( aAnch );
849 SwNode* pMovedNode =
nullptr;
915 assert(ins.getLength() ==
m_aEndStr->getLength());
921 else if (
m_aSttStr && bNodeMove && pInsNd ==
nullptr)
926 if (m_nSttContent < pNd->GetText().getLength())
980 aPos.
Assign( aCopyIndex );
998 if (pTextNd !=
nullptr)
1013 assert(ins.getLength() ==
m_aSttStr->getLength());
1026 if( m_nSetPos < m_pHistory->
Count() )
1049 static_cast<SwContentNode*
>(pNode)->ResetAttr( nStt, nEnd );
1057 assert(&aIdx.
GetNode() == pInsNd);
1066 SwTextNode * pFirstMergedDeletedTextNode(
nullptr);
1071 bool bNonMerged(
false);
1072 std::vector<SwTextFrame*> frames;
1076 if (pFrame->getRootFrame()->HasMergedParas())
1078 frames.push_back(pFrame);
1093 pFrame->RegisterToNode(*pFirstMergedDeletedTextNode);
1094 assert(pFrame->GetMergedPara());
1095 assert(!bNonMerged);
1097 delFullParaEndNode = pFirstMergedDeletedTextNode->
GetIndex();
1134 ? delFullParaEndNode
1149 assert(&aIdx.
GetNode() == pInsNd);
1150 SwPaM tmp(aIdx, aIdx);
1165 OSL_ENSURE(bSuccess,
1166 "SwUndoDelete::Redo: used to have redline data, but now none?");
1191 OSL_ENSURE( rPam.
HasMark(),
"PaM without Mark" );
1211 OSL_ENSURE( rPam.
HasMark(),
"PaM without Mark" );
1288 assert(!
"dead code");
1330 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwUndoDelete"));
1331 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
1334 (void)xmlTextWriterEndElement(pWriter);
@ ArtificialSelection
keyboard delete, artificial selection, avoid deleting flys
OUString ShortenString(const OUString &rStr, sal_Int32 nLength, std::u16string_view aFillStr)
Shortens a string to a maximum length.
const int nUndoStringLength
bool isLetterNumeric(const OUString &rStr, sal_Int32 nPos) const
virtual bool DeleteAndJoin(SwPaM &, SwDeleteFlags flags=SwDeleteFlags::Default)=0
complete delete of a given PaM
virtual bool SplitNode(const SwPosition &rPos, bool bChkTableStart)=0
Split a node at rPos (implemented only for TextNode).
virtual bool DelFullPara(SwPaM &)=0
Delete full paragraphs.
virtual bool IsIgnoreRedline() const =0
virtual bool DeleteRedline(const SwPaM &rPam, bool bSaveInUndo, RedlineType nDelType)=0
virtual const SwRedlineTable & GetRedlineTable() const =0
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Marks a character position inside a document model content node (SwContentNode)
bool HasSwAttrSet() const
virtual bool SetAttr(const SfxPoolItem &)
made virtual
const SwAttrSet * GetpSwAttrSet() const
IDocumentContentOperations const & getIDocumentContentOperations() const
IDocumentUndoRedo & GetIDocumentUndoRedo()
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
const SwTextFormatColl * GetDfltTextFormatColl() const
const sw::FrameFormats< sw::SpzFrameFormat * > * GetSpzFrameFormats() const
::sw::UndoManager & GetUndoManager()
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
void Move(sal_uInt16 nPos, SwHistory *pIns, sal_uInt16 const nStart=0)
Marks a node in the document model.
const SwNodes & GetNodes() const
SwNodeOffset GetIndex() const
Base class of the Writer document model elements.
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
SwNodeOffset GetIndex() const
bool IsContentNode() const
bool IsSectionNode() const
const SwStartNode * StartOfSectionNode() const
SwNodeOffset EndOfSectionIndex() const
SwContentNode * GetContentNode()
SwTableNode * GetTableNode()
const SwEndNode * EndOfSectionNode() const
SwTextNode * MakeTextNode(SwNode &rWhere, SwTextFormatColl *pColl, bool bNewFrames=true)
Implementations of "Make...Node" are in the given .cxx-files.
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
bool MoveNodes(const SwNodeRange &, SwNodes &rNodes, SwNode &rPos, bool bNewFrames=true)
move the node pointer
void Delete(const SwNodeIndex &rPos, SwNodeOffset nNodes=SwNodeOffset(1))
void Copy_(const SwNodeRange &rRg, SwNode &rInsPos, bool bNewFrames=true) const
SwNodeOffset Count() const
PaM is Point and Mark: a selection of the document model.
const SwPosition * GetMark() const
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
std::pair< const SwPosition *, const SwPosition * > StartEnd() const
Because sometimes the cost of the operator<= can add up.
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
const SwPosition * End() const
const SwPosition * GetPoint() const
const SwPosition * Start() const
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
void AddRule(SwUndoArg eWhat, const OUString &rWith)
static OUString GetPlaceHolder(SwUndoArg eId)
OUString Apply(const OUString &rStr) const
const SwTable & GetTable() const
void DelFrames(SwRootFrame const *pLayout=nullptr)
Method deletes all views of document for the node.
SwTableFormat * GetFrameFormat()
Represents the visualization of a paragraph.
SwTextNode is a paragraph in the document model.
virtual sal_Int32 Len() const override
void ClearSwpHintsArr(bool bDelFields)
void EraseText(const SwContentIndex &rIdx, const sal_Int32 nCount=SAL_MAX_INT32, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
delete text content ATTENTION: must not be called with a range that overlaps the start of an attribut...
OUString InsertText(const OUString &rStr, const SwContentIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
SwpHints * GetpSwpHints()
const OUString & GetText() const
SwTextFormatColl * GetTextColl() const
virtual sal_uInt16 ResetAllAttr() override
void SetInSwUndo(bool bInUndo)
SwPaM & AddUndoRedoPaM(::sw::UndoRedoContext &, bool const bCorrToContent=false) const
void SetPaM(SwPaM &, bool bCorrToContent=false) const
SwDeleteFlags m_DeleteFlags
virtual void RedoImpl(::sw::UndoRedoContext &) override
void dumpAsXml(xmlTextWriterPtr pWriter) const override
std::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoStart
std::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoEnd
bool SaveContent(const SwPosition *pStt, const SwPosition *pEnd, SwTextNode *pSttTextNd, SwTextNode *pEndTextNd)
virtual void RepeatImpl(::sw::RepeatContext &) override
std::optional< SwNodeIndex > m_oMvStt
std::unique_ptr< SwRedlineSaveDatas > m_pRedlSaveData
virtual SwRewriter GetRewriter() const override
Returns rewriter for this undo object.
virtual ~SwUndoDelete() override
SwUndoDelete(SwPaM &, SwDeleteFlags flags, bool bFullPara=false, bool bCalledByTableCpy=false)
virtual void UndoImpl(::sw::UndoRedoContext &) override
std::optional< OUString > m_aEndStr
SwNodeOffset m_nReplaceDummy
void SetTableName(const OUString &rName)
std::optional< OUString > m_aSttStr
bool CanGrouping(SwDoc &, const SwPaM &)
void DelContentIndex(const SwPosition &pMark, const SwPosition &pPoint, DelContentType nDelContentType=DelContentType::AllMask)
std::unique_ptr< SwHistory > m_pHistory
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
static bool FillSaveData(const SwPaM &rRange, SwRedlineSaveDatas &rSData, bool bDelRange=true, bool bCopyNext=true)
static void SetSaveData(SwDoc &rDoc, SwRedlineSaveDatas &rSData)
static bool CanRedlineGroup(SwRedlineSaveDatas &rCurr, const SwRedlineSaveDatas &rCheck, bool bCurrIsEnd)
void DeRegister()
deregister the currently registered History
Blocks grouping undo actions together into an SfxListUndoAction.
SwNodes const & GetUndoNodes() const
struct _xmlTextWriter * xmlTextWriterPtr
void DelBookmarks(SwNode &rStt, const SwNode &rEnd, std::vector< SaveBookmark > *pSaveBkmk, std::optional< sal_Int32 > oStartContentIdx, std::optional< sal_Int32 > oEndContentIdx)
void PaMCorrAbs(const SwPaM &rRange, const SwPosition &rNewPos)
Function declarations so that everything below the CursorShell can move the Cursor once in a while.
#define CH_TXT_ATR_FIELDSEP
#define CH_TXT_ATR_INPUTFIELDSTART
#define CH_TXT_ATR_FORMELEMENT
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(99)
constexpr TypedWhichId< SvxFormatBreakItem > RES_BREAK(100)
#define CH_TXT_ATR_INPUTFIELDEND
#define CH_TXT_ATR_FIELDEND
#define CH_TXTATR_NEWLINE
#define CH_TXT_ATR_FIELDSTART
#define CH_TXTATR_BREAKWORD
CharClass & GetAppCharClass()
void RecreateStartTextFrames(SwTextNode &rNode)
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
bool GoInNode(SwPaM &rPam, SwMoveFnCollection const &fnMove)
bool GoInContent(SwPaM &rPam, SwMoveFnCollection const &fnMove)
SwMoveFnCollection const & fnMoveBackward
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
@ RES_POOLCOLL_STANDARD
Standard.
Marks a position in the document model.
void Adjust(SwNodeOffset nDelta)
Adjust node position, and resets content position to zero.
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
SwNodeOffset GetNodeIndex() const
sal_Int32 GetContentIndex() const
OUString SwResId(TranslateId aId)
static SwRewriter lcl_RewriterFromHistory(SwHistory &rHistory)
static OUString lcl_DenotedPortion(std::u16string_view rStr, sal_Int32 nStart, sal_Int32 nEnd, bool bQuoted)
static void DelFullParaMoveFrames(SwDoc &rDoc, SwUndRng const &rRange, SwRedlineSaveDatas const &rRedlineSaveData)
static void lcl_MakeAutoFrames(const sw::FrameFormats< sw::SpzFrameFormat * > &rSpzs, SwNodeOffset nMovedIndex)
static void lcl_ReAnchorAtContentFlyFrames(const sw::FrameFormats< sw::SpzFrameFormat * > &rSpzs, const SwPosition &rPos, SwNodeOffset nOldIdx)
static SwTextNode * FindFirstAndNextNode(SwDoc &rDoc, SwUndRng const &rRange, SwRedlineSaveDatas const &rRedlineSaveData, SwTextNode *&o_rpFirstMergedDeletedTextNode)
OUString DenoteSpecialCharacters(std::u16string_view aStr, bool bQuoted)
Denotes special characters in a string.
static bool lcl_IsSpecialCharacter(sal_Unicode nChar)
bool IsFlySelectedByCursor(SwDoc const &rDoc, SwPosition const &rStart, SwPosition const &rEnd)
check at-char and at-para flys in rDoc