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