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