LibreOffice Module sw (master)  1
undel.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <UndoDelete.hxx>
21 #include <hintids.hxx>
22 #include <unotools/charclass.hxx>
23 #include <frmfmt.hxx>
24 #include <fmtanchr.hxx>
25 #include <doc.hxx>
26 #include <UndoManager.hxx>
29 #include <swtable.hxx>
30 #include <swundo.hxx>
31 #include <pam.hxx>
32 #include <ndtxt.hxx>
33 #include <UndoCore.hxx>
34 #include <rolbck.hxx>
35 #include <poolfmt.hxx>
36 #include <mvsave.hxx>
37 #include <docary.hxx>
38 #include <frmtool.hxx>
39 #include <txtfrm.hxx>
40 #include <rootfrm.hxx>
41 #include <strings.hrc>
42 #include <frameformats.hxx>
43 #include <vector>
44 
45 // DELETE
46 /* lcl_MakeAutoFrames has to call MakeFrames for objects bounded "AtChar"
47  ( == AUTO ), if the anchor frame has be moved via MoveNodes(..) and
48  DelFrames(..)
49 */
50 static void lcl_MakeAutoFrames( const SwFrameFormats& rSpzArr, sal_uLong nMovedIndex )
51 {
52  for( size_t n = 0; n < rSpzArr.size(); ++n )
53  {
54  SwFrameFormat * pFormat = rSpzArr[n];
55  const SwFormatAnchor* pAnchor = &pFormat->GetAnchor();
56  if (pAnchor->GetAnchorId() == RndStdIds::FLY_AT_CHAR)
57  {
58  const SwPosition* pAPos = pAnchor->GetContentAnchor();
59  if( pAPos && nMovedIndex == pAPos->nNode.GetIndex() )
60  pFormat->MakeFrames();
61  }
62  }
63 }
64 
65 static SwTextNode * FindFirstAndNextNode(SwDoc & rDoc, SwUndRng const& rRange,
66  SwRedlineSaveDatas const& rRedlineSaveData,
67  SwTextNode *& o_rpFirstMergedDeletedTextNode)
68 {
69  // redlines are corrected now to exclude the deleted node
70  assert(rRange.m_nEndContent == 0);
71  sal_uLong nEndOfRedline = 0;
72  for (size_t i = 0; i < rRedlineSaveData.size(); ++i)
73  {
74  auto const& rRedline(rRedlineSaveData[i]);
75  if (rRedline.m_nSttNode <= rRange.m_nSttNode
76  && rRedline.m_nSttNode < rRange.m_nEndNode
77  && rRange.m_nEndNode <= rRedline.m_nEndNode
78  && rRedline.GetType() == RedlineType::Delete)
79  {
80  nEndOfRedline = rRedline.m_nEndNode;
81  o_rpFirstMergedDeletedTextNode = rDoc.GetNodes()[rRedline.m_nSttNode]->GetTextNode();
82  assert(rRange.m_nSttNode == rRange.m_nEndNode - 1); // otherwise this needs to iterate more RL to find the first node?
83  break;
84  }
85  }
86  if (nEndOfRedline)
87  {
88  assert(o_rpFirstMergedDeletedTextNode);
89  SwTextNode * pNextNode(nullptr);
90  for (sal_uLong i = rRange.m_nEndNode; /* i <= nEndOfRedline */; ++i)
91  {
92  SwNode *const pNode(rDoc.GetNodes()[i]);
93  assert(!pNode->IsEndNode()); // cannot be both leaving section here *and* overlapping redline
94  if (pNode->IsStartNode())
95  {
96  i = pNode->EndOfSectionIndex(); // will be incremented again
97  }
98  else if (pNode->IsTextNode())
99  {
100  pNextNode = pNode->GetTextNode();
101  break;
102  }
103  }
104  assert(pNextNode);
105  return pNextNode;
106  }
107  else
108  {
109  return nullptr;
110  }
111 }
112 
113 static void DelFullParaMoveFrames(SwDoc & rDoc, SwUndRng const& rRange,
114  SwRedlineSaveDatas const& rRedlineSaveData)
115 {
116  SwTextNode * pFirstMergedDeletedTextNode(nullptr);
117  SwTextNode *const pNextNode = FindFirstAndNextNode(rDoc, rRange,
118  rRedlineSaveData, pFirstMergedDeletedTextNode);
119  if (pNextNode)
120  {
121  std::vector<SwTextFrame*> frames;
122  SwIterator<SwTextFrame, SwTextNode, sw::IteratorMode::UnwrapMulti> aIter(*pFirstMergedDeletedTextNode);
123  for (SwTextFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next())
124  {
125  if (pFrame->getRootFrame()->IsHideRedlines())
126  {
127  assert(pFrame->GetMergedPara());
128  assert(pFrame->GetMergedPara()->pFirstNode == pFirstMergedDeletedTextNode);
129  assert(pNextNode->GetIndex() <= pFrame->GetMergedPara()->pLastNode->GetIndex());
130  frames.push_back(pFrame);
131  }
132  }
133  for (SwTextFrame *const pFrame : frames)
134  {
135  // sw_redlinehide: don't need FrameMode::Existing here
136  // because everything from pNextNode onwards is already
137  // correctly hidden
138  pFrame->RegisterToNode(*pNextNode, true);
139  }
140  }
141 }
142 
143 // SwUndoDelete has to perform a deletion and to record anything that is needed
144 // to restore the situation before the deletion. Unfortunately a part of the
145 // deletion will be done after calling this Ctor, this has to be kept in mind!
146 // In this Ctor only the complete paragraphs will be deleted, the joining of
147 // the first and last paragraph of the selection will be handled outside this
148 // function.
149 // Here are the main steps of the function:
150 // 1. Deletion/recording of content indices of the selection: footnotes, fly
151 // frames and bookmarks
152 // Step 1 could shift all nodes by deletion of footnotes => nNdDiff will be set.
153 // 2. If the paragraph where the selection ends, is the last content of a
154 // section so that this section becomes empty when the paragraphs will be
155 // joined we have to do some smart actions ;-) The paragraph will be moved
156 // outside the section and replaced by a dummy text node, the complete
157 // section will be deleted in step 3. The difference between replacement
158 // dummy and original is nReplacementDummy.
159 // 3. Moving complete selected nodes into the UndoArray. Before this happens the
160 // selection has to be extended if there are sections which would become
161 // empty otherwise. BTW: sections will be moved into the UndoArray if they
162 // are complete part of the selection. Sections starting or ending outside
163 // of the selection will not be removed from the DocNodeArray even they got
164 // a "dummy"-copy in the UndoArray.
165 // 4. We have to anticipate the joining of the two paragraphs if the start
166 // paragraph is inside a section and the end paragraph not. Then we have to
167 // move the paragraph into this section and to record this in nSectDiff.
169  SwPaM& rPam,
170  bool bFullPara,
171  bool bCalledByTableCpy )
172  : SwUndo(SwUndoId::DELETE, rPam.GetDoc()),
173  SwUndRng( rPam ),
174  m_nNode(0),
175  m_nNdDiff(0),
176  m_nSectDiff(0),
177  m_nReplaceDummy(0),
178  m_nSetPos(0),
179  m_bGroup( false ),
180  m_bBackSp( false ),
181  m_bJoinNext( false ),
182  m_bTableDelLastNd( false ),
183  // bFullPara is set e.g. if an empty paragraph before a table is deleted
184  m_bDelFullPara( bFullPara ),
185  m_bResetPgDesc( false ),
186  m_bResetPgBrk( false ),
187  m_bFromTableCopy( bCalledByTableCpy )
188 {
189 
190  m_bCacheComment = false;
191 
192  SwDoc * pDoc = rPam.GetDoc();
193 
195  {
197  if( !FillSaveData( rPam, *m_pRedlSaveData ))
198  {
199  m_pRedlSaveData.reset();
200  }
201  }
202 
203  if( !m_pHistory )
204  m_pHistory.reset( new SwHistory );
205 
206  // delete all footnotes for now
207  const SwPosition *pStt = rPam.Start(),
208  *pEnd = rPam.GetPoint() == pStt
209  ? rPam.GetMark()
210  : rPam.GetPoint();
211 
212  // Step 1. deletion/record of content indices
213  if( m_bDelFullPara )
214  {
215  OSL_ENSURE( rPam.HasMark(), "PaM without Mark" );
216  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint(),
218 
219  ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
220  DelBookmarks(pStt->nNode, pEnd->nNode);
221  }
222  else
223  {
224  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint() );
225  ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
226  if (m_nEndNode - m_nSttNode > 1) // check for fully selected nodes
227  {
228  SwNodeIndex const start(pStt->nNode, +1);
229  DelBookmarks(start, pEnd->nNode);
230  }
231  }
232 
233  m_nSetPos = m_pHistory ? m_pHistory->Count() : 0;
234 
235  // Is already anything deleted?
236  m_nNdDiff = m_nSttNode - pStt->nNode.GetIndex();
237 
238  m_bJoinNext = !bFullPara && pEnd == rPam.GetPoint();
239  m_bBackSp = !bFullPara && !m_bJoinNext;
240 
241  SwTextNode *pSttTextNd = nullptr, *pEndTextNd = nullptr;
242  if( !bFullPara )
243  {
244  pSttTextNd = pStt->nNode.GetNode().GetTextNode();
245  pEndTextNd = m_nSttNode == m_nEndNode
246  ? pSttTextNd
247  : pEnd->nNode.GetNode().GetTextNode();
248  }
249  else if (m_pRedlSaveData)
250  {
251  DelFullParaMoveFrames(*pDoc, *this, *m_pRedlSaveData);
252  }
253 
254  bool bMoveNds = *pStt != *pEnd // any area still existent?
255  && ( SaveContent( pStt, pEnd, pSttTextNd, pEndTextNd ) || m_bFromTableCopy );
256 
257  if( pSttTextNd && pEndTextNd && pSttTextNd != pEndTextNd )
258  {
259  // two different TextNodes, thus save also the TextFormatCollection
260  m_pHistory->Add( pSttTextNd->GetTextColl(),pStt->nNode.GetIndex(), SwNodeType::Text );
261  m_pHistory->Add( pEndTextNd->GetTextColl(),pEnd->nNode.GetIndex(), SwNodeType::Text );
262 
263  if( !m_bJoinNext ) // Selection from bottom to top
264  {
265  // When using JoinPrev() all AUTO-PageBreak's will be copied
266  // correctly. To restore them with UNDO, Auto-PageBreak of the
267  // EndNode needs to be reset. Same for PageDesc and ColBreak.
268  if( pEndTextNd->HasSwAttrSet() )
269  {
270  SwRegHistory aRegHist( *pEndTextNd, m_pHistory.get() );
271  if( SfxItemState::SET == pEndTextNd->GetpSwAttrSet()->GetItemState(
272  RES_BREAK, false ) )
273  pEndTextNd->ResetAttr( RES_BREAK );
274  if( pEndTextNd->HasSwAttrSet() &&
275  SfxItemState::SET == pEndTextNd->GetpSwAttrSet()->GetItemState(
276  RES_PAGEDESC, false ) )
277  pEndTextNd->ResetAttr( RES_PAGEDESC );
278  }
279  }
280  }
281 
282  // Move now also the PaM. The SPoint is at the beginning of a SSelection.
283  if( pEnd == rPam.GetPoint() && ( !bFullPara || pSttTextNd || pEndTextNd ) )
284  rPam.Exchange();
285 
286  if( !pSttTextNd && !pEndTextNd )
287  --rPam.GetPoint()->nNode;
288  rPam.DeleteMark(); // the SPoint is in the selection
289 
290  if( !pEndTextNd )
291  m_nEndContent = 0;
292  if( !pSttTextNd )
293  m_nSttContent = 0;
294 
295  if( bMoveNds ) // Do Nodes exist that need to be moved?
296  {
297  SwNodes& rNds = pDoc->GetUndoManager().GetUndoNodes();
298  SwNodes& rDocNds = pDoc->GetNodes();
299  SwNodeRange aRg( rDocNds, m_nSttNode - m_nNdDiff,
300  rDocNds, m_nEndNode - m_nNdDiff );
301  if( !bFullPara && !pEndTextNd &&
302  &aRg.aEnd.GetNode() != &pDoc->GetNodes().GetEndOfContent() )
303  {
304  SwNode* pNode = aRg.aEnd.GetNode().StartOfSectionNode();
305  if( pNode->GetIndex() >= m_nSttNode - m_nNdDiff )
306  ++aRg.aEnd; // Deletion of a complete table
307  }
308  SwNode* pTmpNd;
309  // Step 2: Expand selection if necessary
310  if( m_bJoinNext || bFullPara )
311  {
312  // If all content of a section will be moved into Undo, the section
313  // itself should be moved completely.
314  while( aRg.aEnd.GetIndex() + 2 < rDocNds.Count() &&
315  ( (pTmpNd = rDocNds[ aRg.aEnd.GetIndex()+1 ])->IsEndNode() &&
316  pTmpNd->StartOfSectionNode()->IsSectionNode() &&
317  pTmpNd->StartOfSectionNode()->GetIndex() >= aRg.aStart.GetIndex() ) )
318  ++aRg.aEnd;
320  if( m_nReplaceDummy )
321  { // The selection has been expanded, because
322  ++aRg.aEnd;
323  if( pEndTextNd )
324  {
325  // The end text node has to leave the (expanded) selection
326  // The dummy is needed because MoveNodes deletes empty
327  // sections
328  ++m_nReplaceDummy;
329  SwNodeRange aMvRg( *pEndTextNd, 0, *pEndTextNd, 1 );
330  SwPosition aSplitPos( *pEndTextNd );
331  ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
332  pDoc->getIDocumentContentOperations().SplitNode( aSplitPos, false );
333  rDocNds.MoveNodes( aMvRg, rDocNds, aRg.aEnd );
334  --aRg.aEnd;
335  }
336  else
337  m_nReplaceDummy = 0;
338  }
339  }
340  if( m_bBackSp || bFullPara )
341  {
342  // See above, the selection has to be expanded if there are "nearly
343  // empty" sections and a replacement dummy has to be set if needed.
344  while( 1 < aRg.aStart.GetIndex() &&
345  ( (pTmpNd = rDocNds[ aRg.aStart.GetIndex()-1 ])->IsSectionNode() &&
346  pTmpNd->EndOfSectionIndex() < aRg.aEnd.GetIndex() ) )
347  --aRg.aStart;
348  if( pSttTextNd )
349  {
351  if( m_nReplaceDummy )
352  {
353  SwNodeRange aMvRg( *pSttTextNd, 0, *pSttTextNd, 1 );
354  SwPosition aSplitPos( *pSttTextNd );
355  ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
356  pDoc->getIDocumentContentOperations().SplitNode( aSplitPos, false );
357  rDocNds.MoveNodes( aMvRg, rDocNds, aRg.aStart );
358  --aRg.aStart;
359  }
360  }
361  }
362 
363  if( m_bFromTableCopy )
364  {
365  if( !pEndTextNd )
366  {
367  if( pSttTextNd )
368  ++aRg.aStart;
369  else if( !bFullPara && !aRg.aEnd.GetNode().IsContentNode() )
370  --aRg.aEnd;
371  }
372  }
373  else if (pSttTextNd && (pEndTextNd || pSttTextNd->GetText().getLength()))
374  ++aRg.aStart;
375 
376  // Step 3: Moving into UndoArray...
377  m_nNode = rNds.GetEndOfContent().GetIndex();
378  rDocNds.MoveNodes( aRg, rNds, SwNodeIndex( rNds.GetEndOfContent() ));
379  m_pMvStt.reset( new SwNodeIndex( rNds, m_nNode ) );
380  // remember difference!
382 
383  if( pSttTextNd && pEndTextNd )
384  {
385  //Step 4: Moving around sections
386  m_nSectDiff = aRg.aEnd.GetIndex() - aRg.aStart.GetIndex();
387  // nSect is the number of sections which starts(ends) between start
388  // and end node of the selection. The "loser" paragraph has to be
389  // moved into the section(s) of the "winner" paragraph
390  if( m_nSectDiff )
391  {
392  if( m_bJoinNext )
393  {
394  SwNodeRange aMvRg( *pEndTextNd, 0, *pEndTextNd, 1 );
395  rDocNds.MoveNodes( aMvRg, rDocNds, aRg.aStart );
396  }
397  else
398  {
399  SwNodeRange aMvRg( *pSttTextNd, 0, *pSttTextNd, 1 );
400  rDocNds.MoveNodes( aMvRg, rDocNds, aRg.aEnd );
401  }
402  }
403  }
406  m_bJoinNext ? pEndTextNd->GetIndex() : pSttTextNd->GetIndex() );
407  }
408  else
409  m_nNode = 0; // moved no node -> no difference at the end
410 
411  // Are there any Nodes that got deleted before that (FootNotes
412  // have ContentNodes)?
413  if( !pSttTextNd && !pEndTextNd )
414  {
415  m_nNdDiff = m_nSttNode - rPam.GetPoint()->nNode.GetIndex() - (bFullPara ? 0 : 1);
416  rPam.Move( fnMoveForward, GoInNode );
417  }
418  else
419  {
421  if( m_nSectDiff && m_bBackSp )
423  m_nNdDiff -= rPam.GetPoint()->nNode.GetIndex();
424  }
425 
426  if( !rPam.GetNode().IsContentNode() )
427  rPam.GetPoint()->nContent.Assign( nullptr, 0 );
428 
429  // is a history necessary here at all?
430  if( m_pHistory && !m_pHistory->Count() )
431  m_pHistory.reset();
432 }
433 
434 bool SwUndoDelete::SaveContent( const SwPosition* pStt, const SwPosition* pEnd,
435  SwTextNode* pSttTextNd, SwTextNode* pEndTextNd )
436 {
437  sal_uLong nNdIdx = pStt->nNode.GetIndex();
438  // 1 - copy start in Start-String
439  if( pSttTextNd )
440  {
441  bool bOneNode = m_nSttNode == m_nEndNode;
442  SwRegHistory aRHst( *pSttTextNd, m_pHistory.get() );
443  // always save all text atttibutes because of possibly overlapping
444  // areas of on/off
445  m_pHistory->CopyAttr( pSttTextNd->GetpSwpHints(), nNdIdx,
446  0, pSttTextNd->GetText().getLength(), true );
447  if( !bOneNode && pSttTextNd->HasSwAttrSet() )
448  m_pHistory->CopyFormatAttr( *pSttTextNd->GetpSwAttrSet(), nNdIdx );
449 
450  // the length might have changed (!!Fields!!)
451  sal_Int32 nLen = (bOneNode
452  ? pEnd->nContent.GetIndex()
453  : pSttTextNd->GetText().getLength())
454  - pStt->nContent.GetIndex();
455 
456  // delete now also the text (all attribute changes are added to
457  // UNDO history)
458  m_aSttStr = pSttTextNd->GetText().copy(m_nSttContent, nLen);
459  pSttTextNd->EraseText( pStt->nContent, nLen );
460  if( pSttTextNd->GetpSwpHints() )
461  pSttTextNd->GetpSwpHints()->DeRegister();
462 
463  // METADATA: store
464  bool emptied( !m_aSttStr->isEmpty() && !pSttTextNd->Len() );
465  if (!bOneNode || emptied) // merging may overwrite xmlids...
466  {
467  m_pMetadataUndoStart = emptied
468  ? pSttTextNd->CreateUndoForDelete()
469  : pSttTextNd->CreateUndo();
470  }
471 
472  if( bOneNode )
473  return false; // stop moving more nodes
474  }
475 
476  // 2 - copy end into End-String
477  if( pEndTextNd )
478  {
479  SwIndex aEndIdx( pEndTextNd );
480  nNdIdx = pEnd->nNode.GetIndex();
481  SwRegHistory aRHst( *pEndTextNd, m_pHistory.get() );
482 
483  // always save all text atttibutes because of possibly overlapping
484  // areas of on/off
485  m_pHistory->CopyAttr( pEndTextNd->GetpSwpHints(), nNdIdx, 0,
486  pEndTextNd->GetText().getLength(), true );
487 
488  if( pEndTextNd->HasSwAttrSet() )
489  m_pHistory->CopyFormatAttr( *pEndTextNd->GetpSwAttrSet(), nNdIdx );
490 
491  // delete now also the text (all attribute changes are added to
492  // UNDO history)
493  m_aEndStr = pEndTextNd->GetText().copy( 0, pEnd->nContent.GetIndex() );
494  pEndTextNd->EraseText( aEndIdx, pEnd->nContent.GetIndex() );
495  if( pEndTextNd->GetpSwpHints() )
496  pEndTextNd->GetpSwpHints()->DeRegister();
497 
498  // METADATA: store
499  bool emptied = !m_aEndStr->isEmpty() && !pEndTextNd->Len();
500 
501  m_pMetadataUndoEnd = emptied
502  ? pEndTextNd->CreateUndoForDelete()
503  : pEndTextNd->CreateUndo();
504  }
505 
506  // if there are only two Nodes then we're done
507  if( ( pSttTextNd || pEndTextNd ) && m_nSttNode + 1 == m_nEndNode )
508  return false; // do not move any Node
509 
510  return true; // move Nodes lying in between
511 }
512 
513 bool SwUndoDelete::CanGrouping( SwDoc* pDoc, const SwPaM& rDelPam )
514 {
515  // Is Undo greater than one Node (that is Start and EndString)?
516  if( !m_aSttStr || m_aSttStr->isEmpty() || m_aEndStr )
517  return false;
518 
519  // only the deletion of single char's can be condensed
521  return false;
522 
523  const SwPosition *pStt = rDelPam.Start(),
524  *pEnd = rDelPam.GetPoint() == pStt
525  ? rDelPam.GetMark()
526  : rDelPam.GetPoint();
527 
528  if( pStt->nNode != pEnd->nNode ||
529  pStt->nContent.GetIndex()+1 != pEnd->nContent.GetIndex() ||
530  pEnd->nNode != m_nSttNode )
531  return false;
532 
533  // Distinguish between BackSpace and Delete because the Undo array needs to
534  // be constructed differently!
535  if( pEnd->nContent == m_nSttContent )
536  {
537  if( m_bGroup && !m_bBackSp ) return false;
538  m_bBackSp = true;
539  }
540  else if( pStt->nContent == m_nSttContent )
541  {
542  if( m_bGroup && m_bBackSp ) return false;
543  m_bBackSp = false;
544  }
545  else
546  return false;
547 
548  // are both Nodes (Node/Undo array) TextNodes at all?
549  SwTextNode * pDelTextNd = pStt->nNode.GetNode().GetTextNode();
550  if( !pDelTextNd ) return false;
551 
552  sal_Int32 nUChrPos = m_bBackSp ? 0 : m_aSttStr->getLength()-1;
553  sal_Unicode cDelChar = pDelTextNd->GetText()[ pStt->nContent.GetIndex() ];
554  CharClass& rCC = GetAppCharClass();
555  if( ( CH_TXTATR_BREAKWORD == cDelChar || CH_TXTATR_INWORD == cDelChar ) ||
556  rCC.isLetterNumeric( OUString( cDelChar ), 0 ) !=
557  rCC.isLetterNumeric( *m_aSttStr, nUChrPos ) )
558  return false;
559 
560  {
561  SwRedlineSaveDatas aTmpSav;
562  const bool bSaved = FillSaveData( rDelPam, aTmpSav, false );
563 
564  bool bOk = ( !m_pRedlSaveData && !bSaved ) ||
565  ( m_pRedlSaveData && bSaved &&
567  // aTmpSav.DeleteAndDestroyAll();
568  if( !bOk )
569  return false;
570 
571  pDoc->getIDocumentRedlineAccess().DeleteRedline( rDelPam, false, RedlineType::Any );
572  }
573 
574  // Both 'deletes' can be consolidated, so 'move' the related character
575  if( m_bBackSp )
576  m_nSttContent--; // BackSpace: add char to array!
577  else
578  {
579  m_nEndContent++; // Delete: attach char at the end
580  nUChrPos++;
581  }
582  m_aSttStr = m_aSttStr->replaceAt( nUChrPos, 0, OUString(cDelChar) );
583  pDelTextNd->EraseText( pStt->nContent, 1 );
584 
585  m_bGroup = true;
586  return true;
587 }
588 
590 {
591  if( m_pMvStt ) // Delete also the selection from UndoNodes array
592  {
593  // Insert saves content in IconSection
594  m_pMvStt->GetNode().GetNodes().Delete( *m_pMvStt, m_nNode );
595  m_pMvStt.reset();
596  }
597  m_pRedlSaveData.reset();
598 }
599 
601 {
602  SwRewriter aRewriter;
603 
604  bool bDone = false;
605 
606  for ( sal_uInt16 n = 0; n < rHistory.Count(); n++)
607  {
608  OUString aDescr = rHistory[n]->GetDescription();
609 
610  if (!aDescr.isEmpty())
611  {
612  aRewriter.AddRule(UndoArg2, aDescr);
613 
614  bDone = true;
615  break;
616  }
617  }
618 
619  if (! bDone)
620  {
621  aRewriter.AddRule(UndoArg2, SwResId(STR_FIELD));
622  }
623 
624  return aRewriter;
625 }
626 
628 {
629  switch (nChar)
630  {
631  case CH_TXTATR_BREAKWORD:
632  case CH_TXTATR_INWORD:
633  case CH_TXTATR_TAB:
634  case CH_TXTATR_NEWLINE:
639  case CH_TXT_ATR_FIELDSEP:
640  case CH_TXT_ATR_FIELDEND:
641  return true;
642 
643  default:
644  break;
645  }
646 
647  return false;
648 }
649 
650 static OUString lcl_DenotedPortion(const OUString& rStr, sal_Int32 nStart, sal_Int32 nEnd)
651 {
652  OUString aResult;
653 
654  auto nCount = nEnd - nStart;
655  if (nCount > 0)
656  {
657  sal_Unicode cLast = rStr[nEnd - 1];
658  if (lcl_IsSpecialCharacter(cLast))
659  {
660  switch(cLast)
661  {
662  case CH_TXTATR_TAB:
663  aResult = SwResId(STR_UNDO_TABS, nCount);
664 
665  break;
666  case CH_TXTATR_NEWLINE:
667  aResult = SwResId(STR_UNDO_NLS, nCount);
668 
669  break;
670 
671  case CH_TXTATR_INWORD:
672  case CH_TXTATR_BREAKWORD:
674  break;
675 
680  case CH_TXT_ATR_FIELDSEP:
681  case CH_TXT_ATR_FIELDEND:
682  break; // nothing?
683 
684  default:
685  assert(!"unexpected special character");
686  break;
687  }
688  SwRewriter aRewriter;
689  aRewriter.AddRule(UndoArg1, OUString::number(nCount));
690  aResult = aRewriter.Apply(aResult);
691  }
692  else
693  {
694  aResult = SwResId(STR_START_QUOTE) +
695  rStr.copy(nStart, nCount) +
696  SwResId(STR_END_QUOTE);
697  }
698  }
699 
700  return aResult;
701 }
702 
703 OUString DenoteSpecialCharacters(const OUString & rStr)
704 {
705  OUStringBuffer aResult;
706 
707  if (!rStr.isEmpty())
708  {
709  bool bStart = false;
710  sal_Int32 nStart = 0;
711  sal_Unicode cLast = 0;
712 
713  for( sal_Int32 i = 0; i < rStr.getLength(); i++)
714  {
715  if (lcl_IsSpecialCharacter(rStr[i]))
716  {
717  if (cLast != rStr[i])
718  bStart = true;
719 
720  }
721  else
722  {
723  if (lcl_IsSpecialCharacter(cLast))
724  bStart = true;
725  }
726 
727  if (bStart)
728  {
729  aResult.append(lcl_DenotedPortion(rStr, nStart, i));
730 
731  nStart = i;
732  bStart = false;
733  }
734 
735  cLast = rStr[i];
736  }
737 
738  aResult.append(lcl_DenotedPortion(rStr, nStart, rStr.getLength()));
739  }
740  else
742 
743  return aResult.makeStringAndClear();
744 }
745 
747 {
748  SwRewriter aResult;
749 
750  if (m_nNode != 0)
751  {
752  if (!m_sTableName.isEmpty())
753  {
754 
755  SwRewriter aRewriter;
756  aRewriter.AddRule(UndoArg1, SwResId(STR_START_QUOTE));
757  aRewriter.AddRule(UndoArg2, m_sTableName);
758  aRewriter.AddRule(UndoArg3, SwResId(STR_END_QUOTE));
759 
760  OUString sTmp = aRewriter.Apply(SwResId(STR_TABLE_NAME));
761  aResult.AddRule(UndoArg1, sTmp);
762  }
763  else
764  aResult.AddRule(UndoArg1, SwResId(STR_PARAGRAPHS));
765  }
766  else
767  {
768  OUString aStr;
769 
770  if (m_aSttStr && m_aEndStr && m_aSttStr->isEmpty() &&
771  m_aEndStr->isEmpty())
772  {
773  aStr = SwResId(STR_PARAGRAPH_UNDO);
774  }
775  else
776  {
777  std::optional<OUString> aTmpStr;
778  if (m_aSttStr)
779  aTmpStr = m_aSttStr;
780  else if (m_aEndStr)
781  aTmpStr = m_aEndStr;
782 
783  if (aTmpStr)
784  {
785  aStr = DenoteSpecialCharacters(*aTmpStr);
786  }
787  else
788  {
790  }
791  }
792 
793  aStr = ShortenString(aStr, nUndoStringLength, SwResId(STR_LDOTS));
794  if (m_pHistory)
795  {
797  aStr = aRewriter.Apply(aStr);
798  }
799 
800  aResult.AddRule(UndoArg1, aStr);
801  }
802 
803  return aResult;
804 }
805 
806 // Every object, anchored "AtContent" will be reanchored at rPos
807 static void lcl_ReAnchorAtContentFlyFrames( const SwFrameFormats& rSpzArr, SwPosition &rPos, sal_uLong nOldIdx )
808 {
809  if( !rSpzArr.empty() )
810  {
811  SwFlyFrameFormat* pFormat;
812  const SwFormatAnchor* pAnchor;
813  const SwPosition* pAPos;
814  for( size_t n = 0; n < rSpzArr.size(); ++n )
815  {
816  pFormat = static_cast<SwFlyFrameFormat*>(rSpzArr[n]);
817  pAnchor = &pFormat->GetAnchor();
818  if (pAnchor->GetAnchorId() == RndStdIds::FLY_AT_PARA)
819  {
820  pAPos = pAnchor->GetContentAnchor();
821  if( pAPos && nOldIdx == pAPos->nNode.GetIndex() )
822  {
823  SwFormatAnchor aAnch( *pAnchor );
824  aAnch.SetAnchor( &rPos );
825  pFormat->SetFormatAttr( aAnch );
826  }
827  }
828  }
829  }
830 }
831 
833 {
834  SwDoc& rDoc = rContext.GetDoc();
835 
836  sal_uLong nCalcStt = m_nSttNode - m_nNdDiff;
837 
838  if( m_nSectDiff && m_bBackSp )
839  nCalcStt += m_nSectDiff;
840 
841  SwNodeIndex aIdx(rDoc.GetNodes(), nCalcStt);
842  SwNode* pInsNd = &aIdx.GetNode();
843  SwNode* pMovedNode = nullptr;
844 
845  { // code block so that SwPosition is detached when deleting a Node
846  SwPosition aPos( aIdx );
847  if( !m_bDelFullPara )
848  {
849  if( pInsNd->IsTableNode() )
850  {
851  pInsNd = rDoc.GetNodes().MakeTextNode( aIdx,
852  rDoc.GetDfltTextFormatColl() );
853  --aIdx;
854  aPos.nNode = aIdx;
855  aPos.nContent.Assign( pInsNd->GetContentNode(), m_nSttContent );
856  }
857  else
858  {
859  if( pInsNd->IsContentNode() )
860  aPos.nContent.Assign( static_cast<SwContentNode*>(pInsNd), m_nSttContent );
861  if( !m_bTableDelLastNd )
862  pInsNd = nullptr; // do not delete Node!
863  }
864  }
865  else
866  pInsNd = nullptr; // do not delete Node!
867 
868  bool bNodeMove = 0 != m_nNode;
869 
870  if( m_aEndStr )
871  {
872  // discard attributes since they all saved!
873  SwTextNode* pTextNd = aPos.nNode.GetNode().GetTextNode();
874 
875  if( pTextNd && pTextNd->HasSwAttrSet() )
876  pTextNd->ResetAllAttr();
877 
878  if( pTextNd && pTextNd->GetpSwpHints() )
879  pTextNd->ClearSwpHintsArr( true );
880 
881  if( m_aSttStr && !m_bFromTableCopy )
882  {
883  sal_uLong nOldIdx = aPos.nNode.GetIndex();
884  rDoc.getIDocumentContentOperations().SplitNode( aPos, false );
885  // After the split all objects are anchored at the first
886  // paragraph, but the pHistory of the fly frame formats relies
887  // on anchoring at the start of the selection
888  // => selection backwards needs a correction.
889  if( m_bBackSp )
890  lcl_ReAnchorAtContentFlyFrames(*rDoc.GetSpzFrameFormats(), aPos, nOldIdx);
891  pTextNd = aPos.nNode.GetNode().GetTextNode();
892  }
893  if( pTextNd )
894  {
895  OUString const ins( pTextNd->InsertText(*m_aEndStr, aPos.nContent,
897  assert(ins.getLength() == m_aEndStr->getLength()); // must succeed
898  (void) ins;
899  // METADATA: restore
901  }
902  }
903  else if (m_aSttStr && bNodeMove && pInsNd == nullptr)
904  {
905  SwTextNode * pNd = aPos.nNode.GetNode().GetTextNode();
906  if( pNd )
907  {
908  if (m_nSttContent < pNd->GetText().getLength())
909  {
910  sal_uLong nOldIdx = aPos.nNode.GetIndex();
911  rDoc.getIDocumentContentOperations().SplitNode( aPos, false );
912  if( m_bBackSp )
913  lcl_ReAnchorAtContentFlyFrames(*rDoc.GetSpzFrameFormats(), aPos, nOldIdx);
914  }
915  else
916  ++aPos.nNode;
917  }
918  }
919  if( m_nSectDiff )
920  {
921  sal_uLong nMoveIndex = aPos.nNode.GetIndex();
922  int nDiff = 0;
923  if( m_bJoinNext )
924  {
925  nMoveIndex += m_nSectDiff + 1;
926  pMovedNode = &aPos.nNode.GetNode();
927  }
928  else
929  {
930  nMoveIndex -= m_nSectDiff + 1;
931  ++nDiff;
932  }
933  SwNodeIndex aMvIdx(rDoc.GetNodes(), nMoveIndex);
934  SwNodeRange aRg( aPos.nNode, 0 - nDiff, aPos.nNode, 1 - nDiff );
935  --aPos.nNode;
936  if( !m_bJoinNext )
937  pMovedNode = &aPos.nNode.GetNode();
938  rDoc.GetNodes().MoveNodes(aRg, rDoc.GetNodes(), aMvIdx);
939  ++aPos.nNode;
940  }
941 
942  if( bNodeMove )
943  {
944  SwNodeRange aRange( *m_pMvStt, 0, *m_pMvStt, m_nNode );
945  SwNodeIndex aCopyIndex( aPos.nNode, -1 );
946  rDoc.GetUndoManager().GetUndoNodes().Copy_(aRange, aPos.nNode,
947  // sw_redlinehide: delay creating frames: the flags on the
948  // nodes aren't necessarily up-to-date, and the redlines
949  // from m_pRedlSaveData aren't applied yet...
950  false);
951 
952  if( m_nReplaceDummy )
953  {
954  sal_uLong nMoveIndex;
955  if( m_bJoinNext )
956  {
957  nMoveIndex = m_nEndNode - m_nNdDiff;
958  aPos.nNode = nMoveIndex + m_nReplaceDummy;
959  }
960  else
961  {
962  aPos = SwPosition( aCopyIndex );
963  nMoveIndex = aPos.nNode.GetIndex() + m_nReplaceDummy + 1;
964  }
965  SwNodeIndex aMvIdx(rDoc.GetNodes(), nMoveIndex);
966  SwNodeRange aRg( aPos.nNode, 0, aPos.nNode, 1 );
967  pMovedNode = &aPos.nNode.GetNode();
968  rDoc.GetNodes().MoveNodes(aRg, rDoc.GetNodes(), aMvIdx);
969  rDoc.GetNodes().Delete( aMvIdx);
970  }
971  }
972 
973  if( m_aSttStr )
974  {
975  aPos.nNode = m_nSttNode - m_nNdDiff + ( m_bJoinNext ? 0 : m_nReplaceDummy );
976  SwTextNode * pTextNd = aPos.nNode.GetNode().GetTextNode();
977  // If more than a single Node got deleted, also all "Node"
978  // attributes were saved
979  if (pTextNd != nullptr)
980  {
981  if( pTextNd->HasSwAttrSet() && bNodeMove && !m_aEndStr )
982  pTextNd->ResetAllAttr();
983 
984  if( pTextNd->GetpSwpHints() )
985  pTextNd->ClearSwpHintsArr( true );
986 
987  // SectionNode mode and selection from top to bottom:
988  // -> in StartNode is still the rest of the Join => delete
989  aPos.nContent.Assign( pTextNd, m_nSttContent );
990  OUString const ins( pTextNd->InsertText(*m_aSttStr, aPos.nContent,
992  assert(ins.getLength() == m_aSttStr->getLength()); // must succeed
993  (void) ins;
994  // METADATA: restore
995  pTextNd->RestoreMetadata(m_pMetadataUndoStart);
996  }
997  }
998 
999  if( m_pHistory )
1000  {
1001  m_pHistory->TmpRollback(&rDoc, m_nSetPos, false);
1002  if( m_nSetPos ) // there were Footnodes/FlyFrames
1003  {
1004  // are there others than these ones?
1005  if( m_nSetPos < m_pHistory->Count() )
1006  {
1007  // if so save the attributes of the others
1008  SwHistory aHstr;
1009  aHstr.Move( 0, m_pHistory.get(), m_nSetPos );
1010  m_pHistory->Rollback(&rDoc);
1011  m_pHistory->Move( 0, &aHstr );
1012  }
1013  else
1014  {
1015  m_pHistory->Rollback(&rDoc);
1016  m_pHistory.reset();
1017  }
1018  }
1019  }
1020 
1021  if( m_bResetPgDesc || m_bResetPgBrk )
1022  {
1023  sal_uInt16 nStt = m_bResetPgDesc ? sal_uInt16(RES_PAGEDESC) : sal_uInt16(RES_BREAK);
1024  sal_uInt16 nEnd = m_bResetPgBrk ? sal_uInt16(RES_BREAK) : sal_uInt16(RES_PAGEDESC);
1025 
1026  SwNode* pNode = rDoc.GetNodes()[ m_nEndNode + 1 ];
1027  if( pNode->IsContentNode() )
1028  static_cast<SwContentNode*>(pNode)->ResetAttr( nStt, nEnd );
1029  else if( pNode->IsTableNode() )
1030  static_cast<SwTableNode*>(pNode)->GetTable().GetFrameFormat()->ResetFormatAttr( nStt, nEnd );
1031  }
1032  }
1033  // delete the temporarily added Node
1034  if( pInsNd )
1035  rDoc.GetNodes().Delete( aIdx );
1036  if( m_pRedlSaveData )
1037  SetSaveData(rDoc, *m_pRedlSaveData);
1038 
1039  sal_uLong delFullParaEndNode(m_nEndNode);
1041  {
1042  SwTextNode * pFirstMergedDeletedTextNode(nullptr);
1043  SwTextNode *const pNextNode = FindFirstAndNextNode(rDoc, *this,
1044  *m_pRedlSaveData, pFirstMergedDeletedTextNode);
1045  if (pNextNode)
1046  {
1047  bool bNonMerged(false);
1048  std::vector<SwTextFrame*> frames;
1050  for (SwTextFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next())
1051  {
1052  if (pFrame->getRootFrame()->IsHideRedlines())
1053  {
1054  frames.push_back(pFrame);
1055  }
1056  else
1057  {
1058  bNonMerged = true;
1059  }
1060  }
1061  for (SwTextFrame *const pFrame : frames)
1062  {
1063  // could either destroy the text frames, or move them...
1064  // destroying them would have the advantage that we don't
1065  // need special code to *exclude* pFirstMergedDeletedTextNode
1066  // from MakeFrames for the layouts in Hide mode but not
1067  // layouts in Show mode ...
1068  // ... except that MakeFrames won't create them then :(
1069  pFrame->RegisterToNode(*pFirstMergedDeletedTextNode);
1070  assert(pFrame->GetMergedPara());
1071  assert(!bNonMerged); // delFullParaEndNode is such an awful hack
1072  (void) bNonMerged;
1073  delFullParaEndNode = pFirstMergedDeletedTextNode->GetIndex();
1074  }
1075  }
1076  }
1077  else if (m_aSttStr && (!m_bFromTableCopy || 0 != m_nNode))
1078  {
1079  // only now do we have redlines in the document again; fix up the split
1080  // frames
1081  SwTextNode *const pStartNode(aIdx.GetNodes()[m_nSttNode]->GetTextNode());
1082  assert(pStartNode);
1083  std::vector<SwTextFrame*> frames;
1085  for (SwTextFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next())
1086  {
1087  if (pFrame->getRootFrame()->IsHideRedlines())
1088  {
1089  frames.push_back(pFrame);
1090  }
1091  }
1093  for (SwTextFrame * pFrame : frames)
1094  {
1095  // SplitNode could have moved the original frame to the start node
1096  // & created a new one on end, or could have created new frame on
1097  // start node... grab start node's frame and recreate MergedPara.
1098  SwTextNode & rFirstNode(pFrame->GetMergedPara()
1099  ? *pFrame->GetMergedPara()->pFirstNode
1100  : *pStartNode);
1101  assert(rFirstNode.GetIndex() <= pStartNode->GetIndex());
1102  pFrame->SetMergedPara(sw::CheckParaRedlineMerge(
1103  *pFrame, rFirstNode, eMode));
1104  eMode = sw::FrameMode::New; // Existing is not idempotent!
1105  // note: this may or may not delete frames on the end node
1106  }
1107  }
1108 
1109  // create frames after SetSaveData has recreated redlines
1110  if (0 != m_nNode)
1111  {
1112  // tdf#121031 if the start node is a text node, it already has a frame;
1113  // if it's a table, it does not
1114  // tdf#109376 exception: end on non-text-node -> start node was inserted
1115  SwNodeIndex const start(rDoc.GetNodes(), m_nSttNode +
1116  ((m_bDelFullPara || !rDoc.GetNodes()[m_nSttNode]->IsTextNode() || pInsNd)
1117  ? 0 : 1));
1118  // don't include end node in the range: it may have been merged already
1119  // by the start node, or it may be merged by one of the moved nodes,
1120  // but if it isn't merged, its current frame(s) should be good...
1121  SwNodeIndex const end(rDoc.GetNodes(), m_bDelFullPara ? delFullParaEndNode : m_nEndNode);
1122  ::MakeFrames(&rDoc, start, end);
1123  }
1124 
1125  if (pMovedNode)
1126  { // probably better do this after creating all frames
1127  lcl_MakeAutoFrames(*rDoc.GetSpzFrameFormats(), pMovedNode->GetIndex());
1128  }
1129 
1130  AddUndoRedoPaM(rContext, true);
1131 }
1132 
1134 {
1135  SwPaM & rPam = AddUndoRedoPaM(rContext);
1136  SwDoc& rDoc = *rPam.GetDoc();
1137 
1138  if( m_pRedlSaveData )
1139  {
1140  const bool bSuccess = FillSaveData(rPam, *m_pRedlSaveData);
1141  OSL_ENSURE(bSuccess,
1142  "SwUndoDelete::Redo: used to have redline data, but now none?");
1143  if (!bSuccess)
1144  {
1145  m_pRedlSaveData.reset();
1146  }
1147  }
1148 
1149  if( !m_bDelFullPara )
1150  {
1151  // tdf#128739 correct cursors but do not delete bookmarks yet
1152  ::PaMCorrAbs(rPam, *rPam.End());
1153  SetPaM(rPam);
1154 
1155  if( !m_bJoinNext ) // then restore selection from bottom to top
1156  rPam.Exchange();
1157  }
1158 
1159  if( m_pHistory ) // are the attributes saved?
1160  {
1161  m_pHistory->SetTmpEnd( m_pHistory->Count() );
1162  SwHistory aHstr;
1163  aHstr.Move( 0, m_pHistory.get() );
1164 
1165  if( m_bDelFullPara )
1166  {
1167  OSL_ENSURE( rPam.HasMark(), "PaM without Mark" );
1168  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint(),
1170 
1171  DelBookmarks(rPam.GetMark()->nNode, rPam.GetPoint()->nNode);
1172  }
1173  else
1174  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint() );
1175  m_nSetPos = m_pHistory ? m_pHistory->Count() : 0;
1176 
1177  m_pHistory->Move( m_nSetPos, &aHstr );
1178  }
1179  else
1180  {
1181  if( m_bDelFullPara )
1182  {
1183  OSL_ENSURE( rPam.HasMark(), "PaM without Mark" );
1184  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint(),
1186 
1187  DelBookmarks( rPam.GetMark()->nNode, rPam.GetPoint()->nNode );
1188  }
1189  else
1190  DelContentIndex( *rPam.GetMark(), *rPam.GetPoint() );
1191  m_nSetPos = m_pHistory ? m_pHistory->Count() : 0;
1192  }
1193 
1194  if( !m_aSttStr && !m_aEndStr )
1195  {
1197  {
1198  DelFullParaMoveFrames(rDoc, *this, *m_pRedlSaveData);
1199  }
1200 
1201  SwNodeIndex aSttIdx = ( m_bDelFullPara || m_bJoinNext )
1202  ? rPam.GetMark()->nNode
1203  : rPam.GetPoint()->nNode;
1204  SwTableNode* pTableNd = aSttIdx.GetNode().GetTableNode();
1205  if( pTableNd )
1206  {
1207  if( m_bTableDelLastNd )
1208  {
1209  // than add again a Node at the end
1210  const SwNodeIndex aTmpIdx( *pTableNd->EndOfSectionNode(), 1 );
1211  rDoc.GetNodes().MakeTextNode( aTmpIdx,
1213  }
1214 
1215  SwContentNode* pNextNd = rDoc.GetNodes()[
1216  pTableNd->EndOfSectionIndex()+1 ]->GetContentNode();
1217  if( pNextNd )
1218  {
1219  SwFrameFormat* pTableFormat = pTableNd->GetTable().GetFrameFormat();
1220 
1221  const SfxPoolItem *pItem;
1222  if( SfxItemState::SET == pTableFormat->GetItemState( RES_PAGEDESC,
1223  false, &pItem ) )
1224  pNextNd->SetAttr( *pItem );
1225 
1226  if( SfxItemState::SET == pTableFormat->GetItemState( RES_BREAK,
1227  false, &pItem ) )
1228  pNextNd->SetAttr( *pItem );
1229  }
1230  pTableNd->DelFrames();
1231  }
1232  else if (*rPam.GetMark() == *rPam.GetPoint())
1233  { // paragraph with only footnote or as-char fly, delete that
1234  // => DelContentIndex has already deleted it! nothing to do here
1235  assert(m_nEndNode == m_nSttNode);
1236  return;
1237  }
1238 
1239  // avoid asserts from ~SwIndexReg for deleted nodes
1240  SwPaM aTmp(*rPam.End());
1241  if (!aTmp.Move(fnMoveForward, GoInNode))
1242  {
1243  *aTmp.GetPoint() = *rPam.Start();
1244  aTmp.Move(fnMoveBackward, GoInNode);
1245  }
1246  assert(aTmp.GetPoint()->nNode != rPam.GetPoint()->nNode
1247  && aTmp.GetPoint()->nNode != rPam.GetMark()->nNode);
1248  ::PaMCorrAbs(rPam, *aTmp.GetPoint());
1249 
1250  rPam.DeleteMark();
1251 
1252  rDoc.GetNodes().Delete( aSttIdx, m_nEndNode - m_nSttNode );
1253  }
1254  else if( m_bDelFullPara )
1255  {
1256  assert(!"dead code");
1257  // The Pam was incremented by one at Point (== end) to provide space
1258  // for UNDO. This now needs to be reverted!
1259  --rPam.End()->nNode;
1260  if( rPam.GetPoint()->nNode == rPam.GetMark()->nNode )
1261  *rPam.GetMark() = *rPam.GetPoint();
1263  }
1264  else
1266 }
1267 
1269 {
1270  // this action does not seem idempotent,
1271  // so make sure it is only executed once on repeat
1272  if (rContext.m_bDeleteRepeated)
1273  return;
1274 
1275  SwPaM & rPam = rContext.GetRepeatPaM();
1276  SwDoc& rDoc = *rPam.GetDoc();
1277  ::sw::GroupUndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
1278  if( !rPam.HasMark() )
1279  {
1280  rPam.SetMark();
1281  rPam.Move( fnMoveForward, GoInContent );
1282  }
1283  if( m_bDelFullPara )
1285  else
1287  rContext.m_bDeleteRepeated = true;
1288 }
1289 
1290 void SwUndoDelete::SetTableName(const OUString & rName)
1291 {
1292  m_sTableName = rName;
1293 }
1294 
1295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uLong m_nNdDiff
Definition: UndoDelete.hxx:49
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:682
SwPaM & AddUndoRedoPaM(::sw::UndoRedoContext &, bool const bCorrToContent=false) const
Definition: undobj.cxx:106
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
void DeleteMark()
Definition: pam.hxx:177
sal_uLong GetIndex() const
Definition: node.hxx:282
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
bool GoInContent(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:956
sal_uLong Count() const
Definition: ndarr.hxx:142
static OUString GetPlaceHolder(SwUndoArg eId)
Definition: SwRewriter.cxx:55
Marks a position in the document model.
Definition: pam.hxx:35
void DelBookmarks(const SwNodeIndex &rStt, const SwNodeIndex &rEnd, std::vector< SaveBookmark > *pSaveBkmk, const SwIndex *pSttIdx, const SwIndex *pEndIdx)
Definition: docbm.cxx:1785
bool IsSectionNode() const
Definition: node.hxx:644
std::unique_ptr< SwHistory > m_pHistory
Definition: undobj.hxx:161
SwNodes const & GetUndoNodes() const
Definition: docundo.cxx:71
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: undel.cxx:1133
void DelFrames(SwRootFrame const *pLayout=nullptr)
Method deletes all views of document for the node.
Definition: ndtbl.cxx:2415
const OUString & GetText() const
Definition: ndtxt.hxx:211
SwUndoId
Definition: swundo.hxx:29
virtual sal_uInt16 ResetAllAttr() override
Definition: ndtxt.cxx:5142
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:219
std::unique_ptr< SwNodeIndex > m_pMvStt
Definition: UndoDelete.hxx:40
size_t size() const
Definition: UndoCore.hxx:76
SwNodeIndex nNode
Definition: pam.hxx:37
sal_uLong m_nNode
Definition: UndoDelete.hxx:48
virtual sal_Int32 Len() const override
Definition: ndtxt.cxx:274
sal_uIntPtr sal_uLong
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:128
const SwPosition * GetMark() const
Definition: pam.hxx:209
sal_uLong m_nEndNode
Definition: undobj.hxx:223
sal_Int64 n
bool SaveContent(const SwPosition *pStt, const SwPosition *pEnd, SwTextNode *pSttTextNd, SwTextNode *pEndTextNd)
Definition: undel.cxx:434
Definition: doc.hxx:186
TElementType * Next()
Definition: calbck.hxx:373
sal_uInt16 m_nSetPos
Definition: UndoDelete.hxx:52
bool m_bJoinNext
Definition: UndoDelete.hxx:56
SwNode & GetNode() const
Definition: ndindex.hxx:119
#define CH_TXTATR_NEWLINE
Definition: hintids.hxx:139
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:143
virtual bool DeleteAndJoin(SwPaM &, const bool bForceJoinNext=false)=0
complete delete of a given PaM
std::optional< OUString > m_aEndStr
Definition: UndoDelete.hxx:41
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:314
#define CH_TXT_ATR_FORMELEMENT
Definition: hintids.hxx:143
void Copy_(const SwNodeRange &rRg, const SwNodeIndex &rInsPos, bool bNewFrames=true) const
Definition: ndarr.hxx:176
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:201
const SwFrameFormats * GetSpzFrameFormats() const
Definition: doc.hxx:741
static SwTextNode * FindFirstAndNextNode(SwDoc &rDoc, SwUndRng const &rRange, SwRedlineSaveDatas const &rRedlineSaveData, SwTextNode *&o_rpFirstMergedDeletedTextNode)
Definition: undel.cxx:65
virtual SwRewriter GetRewriter() const override
Returns rewriter for this undo object.
Definition: undel.cxx:746
bool CanGrouping(SwDoc *, const SwPaM &)
Definition: undel.cxx:513
std::shared_ptr< MetadatableUndo > CreateUndoForDelete()
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:136
void Delete(const SwNodeIndex &rPos, sal_uLong nNodes=1)
delete nodes
Definition: nodes.cxx:1065
bool isLetterNumeric(const OUString &rStr, sal_Int32 nPos) const
sal_uInt16 sal_Unicode
bool m_bResetPgBrk
Definition: UndoDelete.hxx:60
#define CH_TXTATR_INWORD
Definition: hintids.hxx:137
SwTableNode * GetTableNode()
Definition: node.hxx:599
SwUndoDelete(SwPaM &, bool bFullPara=false, bool bCalledByTableCpy=false)
Definition: undel.cxx:168
SwIndex nContent
Definition: pam.hxx:38
bool empty() const
Definition: docary.hxx:265
sal_uLong m_nReplaceDummy
Definition: UndoDelete.hxx:51
SwNodeIndex aStart
Definition: ndindex.hxx:132
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:425
const SwTextFormatColl * GetDfltTextFormatColl() const
Definition: doc.hxx:775
std::unique_ptr< sw::MergedPara > CheckParaRedlineMerge(SwTextFrame &rFrame, SwTextNode &rTextNode, FrameMode eMode)
Definition: redlnitr.cxx:53
#define CH_TXT_ATR_INPUTFIELDSTART
Definition: hintids.hxx:140
int nCount
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
Mode eMode
const SwTable & GetTable() const
Definition: node.hxx:497
static bool CanRedlineGroup(SwRedlineSaveDatas &rCurr, const SwRedlineSaveDatas &rCheck, bool bCurrIsEnd)
Definition: undobj.cxx:1467
bool empty() const
bool m_bFromTableCopy
Definition: UndoDelete.hxx:61
SwDoc & GetDoc() const
Definition: UndoCore.hxx:94
static OUString lcl_DenotedPortion(const OUString &rStr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: undel.cxx:650
virtual ~SwUndoDelete() override
Definition: undel.cxx:589
void MakeFrames(SwDoc *pDoc, const SwNodeIndex &rSttIdx, const SwNodeIndex &rEndIdx)
Definition: frmtool.cxx:1833
Specific frame formats (frames, DrawObjects).
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:163
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: undel.cxx:1268
void SetTableName(const OUString &rName)
Definition: undel.cxx:1290
bool IsContentNode() const
Definition: node.hxx:628
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:443
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:496
Style of a layout element.
Definition: frmfmt.hxx:57
::sw::UndoManager & GetUndoManager()
Definition: doc.cxx:132
void DeRegister()
deregister the currently registered History
Definition: ndhints.hxx:197
std::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoEnd
Definition: UndoDelete.hxx:44
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:81
bool m_bDelFullPara
Definition: UndoDelete.hxx:58
int i
bool GoInNode(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:947
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
const SwPosition * GetPoint() const
Definition: pam.hxx:207
void DelContentIndex(const SwPosition &pMark, const SwPosition &pPoint, DelContentType nDelContentType=DelContentType::AllMask)
Definition: undobj.cxx:847
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:198
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:65
OUString Apply(const OUString &rStr) const
Definition: SwRewriter.cxx:43
const SwPosition * GetContentAnchor() const
Definition: fmtanchr.hxx:67
Count
static void SetSaveData(SwDoc &rDoc, SwRedlineSaveDatas &rSData)
Definition: undobj.cxx:1440
static SwRewriter lcl_RewriterFromHistory(SwHistory &rHistory)
Definition: undel.cxx:600
void Exchange()
Definition: pam.cxx:484
TElementType * First()
Definition: calbck.hxx:342
virtual bool DeleteRedline(const SwPaM &rPam, bool bSaveInUndo, RedlineType nDelType)=0
bool m_bTableDelLastNd
Definition: UndoDelete.hxx:57
FlyAnchors.
Definition: fmtanchr.hxx:34
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
sal_Int32 m_nEndContent
Definition: undobj.hxx:224
SwDoc * GetDoc() const
Definition: pam.hxx:243
sal_uLong m_nSectDiff
Definition: UndoDelete.hxx:50
static void DelFullParaMoveFrames(SwDoc &rDoc, SwUndRng const &rRange, SwRedlineSaveDatas const &rRedlineSaveData)
Definition: undel.cxx:113
Marks a character position inside a document model node.
Definition: index.hxx:37
#define CH_TXT_ATR_FIELDSTART
Definition: hintids.hxx:145
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:29
std::shared_ptr< MetadatableUndo > CreateUndo() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
Definition: format.cxx:396
Marks a node in the document model.
Definition: ndindex.hxx:31
bool m_bCacheComment
Definition: undobj.hxx:60
bool HasSwAttrSet() const
Definition: node.hxx:444
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
enumrange< T >::Iterator end(enumrange< T >)
const SwPosition * Start() const
Definition: pam.hxx:212
virtual bool IsIgnoreRedline() const =0
static void lcl_MakeAutoFrames(const SwFrameFormats &rSpzArr, sal_uLong nMovedIndex)
Definition: undel.cxx:50
sal_uInt16 Count() const
Definition: rolbck.hxx:372
sal_uLong m_nSttNode
Definition: undobj.hxx:223
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
void EraseText(const SwIndex &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...
Definition: ndtxt.cxx:2660
OUString InsertText(const OUString &rStr, const SwIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2277
void ClearSwpHintsArr(bool bDelFields)
Definition: thints.cxx:3365
sal_uLong EndOfSectionIndex() const
Definition: node.hxx:677
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
#define CH_TXT_ATR_INPUTFIELDEND
Definition: hintids.hxx:141
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:334
bool m_bResetPgDesc
Definition: UndoDelete.hxx:59
virtual bool SetAttr(const SfxPoolItem &)
made virtual
Definition: node.cxx:1496
void SetPaM(SwPaM &, bool bCorrToContent=false) const
Definition: undobj.cxx:78
DelContentType
Definition: undobj.hxx:132
OUString ShortenString(const OUString &rStr, sal_Int32 nLength, const OUString &rFillStr)
Shortens a string to a maximum length.
Definition: undobj.cxx:1499
static void lcl_ReAnchorAtContentFlyFrames(const SwFrameFormats &rSpzArr, SwPosition &rPos, sal_uLong nOldIdx)
Definition: undel.cxx:807
SwMoveFnCollection const & fnMoveForward
SwPam::Move()/Find() default argument.
Definition: paminit.cxx:59
virtual bool DelFullPara(SwPaM &)=0
Delete full paragraphs.
OUString DenoteSpecialCharacters(const OUString &rStr)
Denotes special characters in a string.
Definition: undel.cxx:703
sal_Int32 GetIndex() const
Definition: index.hxx:95
virtual void MakeFrames()
Creates the views.
Definition: atrfrm.cxx:2643
SwNodes & GetNodes()
Definition: doc.hxx:405
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
const SwPosition * End() const
Definition: pam.hxx:217
SwNodeIndex aEnd
Definition: ndindex.hxx:133
#define CH_TXTATR_TAB
Definition: hintids.hxx:138
void PaMCorrAbs(const SwPaM &rRange, const SwPosition &rNewPos)
Function declarations so that everything below the CursorShell can move the Cursor once in a while...
Definition: doccorr.cxx:85
double getLength(const B2DPolygon &rCandidate)
static bool lcl_IsSpecialCharacter(sal_Unicode nChar)
Definition: undel.cxx:627
#define CH_TXT_ATR_FIELDEND
Definition: hintids.hxx:147
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
virtual bool SplitNode(const SwPosition &rPos, bool bChkTableStart)=0
Split a node at rPos (implemented only for TextNode).
bool IsTableNode() const
Definition: node.hxx:640
size_t size() const
std::unique_ptr< SwRedlineSaveDatas > m_pRedlSaveData
Definition: UndoDelete.hxx:42
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:470
static bool FillSaveData(const SwPaM &rRange, SwRedlineSaveDatas &rSData, bool bDelRange=true, bool bCopyNext=true)
Definition: undobj.cxx:1375
virtual const SwRedlineTable & GetRedlineTable() const =0
#define RES_PAGEDESC
Definition: hintids.hxx:293
#define RES_BREAK
Definition: hintids.hxx:294
std::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoStart
Definition: UndoDelete.hxx:43
#define CH_TXT_ATR_FIELDSEP
Definition: hintids.hxx:146
std::optional< OUString > m_aSttStr
Definition: UndoDelete.hxx:41
CharClass & GetAppCharClass()
Definition: init.cxx:709
void Move(sal_uInt16 nPos, SwHistory *pIns, sal_uInt16 const nStart=0)
Definition: rolbck.hxx:380
OUString m_sTableName
Definition: UndoDelete.hxx:46
aStr
void RestoreMetadata(std::shared_ptr< MetadatableUndo > const &i_pUndo)
sal_Int32 m_nSttContent
Definition: undobj.hxx:224
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: undel.cxx:832
const int nUndoStringLength
Definition: UndoCore.hxx:224
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:836
SwTextNode * MakeTextNode(const SwNodeIndex &rWhere, SwTextFormatColl *pColl, bool bNewFrames=true)
Implementations of "Make...Node" are in the given .cxx-files.
Definition: ndtxt.cxx:104
void SetAnchor(const SwPosition *pPos)
Definition: atrfrm.cxx:1478
bool MoveNodes(const SwNodeRange &, SwNodes &rNodes, const SwNodeIndex &, bool bNewFrames=true)
move the node pointer
Definition: nodes.cxx:394
Base class of the Writer document model elements.
Definition: node.hxx:79
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:830
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo