sw/source/core/undo/untblk.cxx      |    5 +++++
 sw/source/filter/basflt/shellio.cxx |   16 ++--------------
 2 files changed, 7 insertions(+), 14 deletions(-)

New commits:
commit 359e5af31c330a137fed6ba3140b77cd759c28bb
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Jan 17 20:25:45 2024 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Thu Jan 18 13:24:45 2024 +0100

    tdf#155917 sw: fix Repeat of Insert File with Fly
    
    There is a fly frame anchored on the 1st node of the inserted file.
    
    On Repeat, first SwUndoInsLayFormat::RepeatImpl() runs and inserts
    another fly, adding 3 nodes before the body of the document, then
    SwUndoInserts::RepeatImpl() creates SwPaM from its stored positions that
    is off by 3 nodes and invalid (crossing cell boundaries).
    
    The problem is that the way the Undo objects are created in
    SwReader::Read() is wrong, and there is alreay a better way not to
    create the SwUndoInsLayFormat manually from the outside but
    automatically in SwUndoInserts::SetInsertRange(), which is already used
    in Paste - why Insert File never used this has always been a mystery.
    
    The only difference appears to be that SwReader::Read() also handled
    at-page anchored flys which SetInsertRange() didn't, as these probably
    can't be part of a Paste, but that is easy to add.
    
    (regression from commit 28b77c89dfcafae82cf2a6d85731b643ff9290e5)
    
    Change-Id: I19d7a4d668ae8bed0986162da6ec5b5ea3118091
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162208
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/core/undo/untblk.cxx b/sw/source/core/undo/untblk.cxx
index fd5c3239c042..158167809712 100644
--- a/sw/source/core/undo/untblk.cxx
+++ b/sw/source/core/undo/untblk.cxx
@@ -176,6 +176,11 @@ bool SwUndoInserts::IsCreateUndoForNewFly(SwFormatAnchor 
const& rAnchor,
 {
     assert(nStartNode <= nEndNode);
 
+    if (rAnchor.GetAnchorId() == RndStdIds::FLY_AT_PAGE)
+    {
+        return true; // needed for SwUndoInserts/SwReader::Read()
+    }
+
     // check all at-char flys at the start/end nodes:
     // ExcludeFlyAtStartEnd will exclude them!
     SwNode const*const pAnchorNode = rAnchor.GetAnchorNode();
diff --git a/sw/source/filter/basflt/shellio.cxx 
b/sw/source/filter/basflt/shellio.cxx
index be3b4ddd2db9..715a183105ae 100644
--- a/sw/source/filter/basflt/shellio.cxx
+++ b/sw/source/filter/basflt/shellio.cxx
@@ -251,9 +251,7 @@ ErrCodeMsg SwReader::Read( const Reader& rOptions )
                 // ok, here IsAlive is a misnomer...
                 if (!aFlyFrameArr.IsAlive(pFrameFormat))
                 {
-                    if  (   (RndStdIds::FLY_AT_PAGE == rAnchor.GetAnchorId())
-                        // TODO: why is this not handled via SetInsertRange?
-                        ||  SwUndoInserts::IsCreateUndoForNewFly(rAnchor,
+                    if (SwUndoInserts::IsCreateUndoForNewFly(rAnchor,
                                 pUndoPam->GetPoint()->GetNodeIndex(),
                                 pUndoPam->GetMark()->GetNodeIndex()))
                     {
@@ -268,16 +266,6 @@ ErrCodeMsg SwReader::Read( const Reader& rOptions )
                         }
                         else
                         {
-                            if( bSaveUndo )
-                            {
-                                
mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
-                                // UGLY: temp. enable undo
-                                mxDoc->GetIDocumentUndoRedo().DoUndo(true);
-                                mxDoc->GetIDocumentUndoRedo().AppendUndo(
-                                    std::make_unique<SwUndoInsLayFormat>( 
pFrameFormat, SwNodeOffset(0), 0 ) );
-                                mxDoc->GetIDocumentUndoRedo().DoUndo(false);
-                                
mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore 
);
-                            }
                             if( pFrameFormat->HasWriterListeners() )
                             {
                                 // Draw-Objects create a Frame when being 
inserted; thus delete them
@@ -313,7 +301,7 @@ ErrCodeMsg SwReader::Read( const Reader& rOptions )
         if( bSaveUndo )
         {
             mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
-            pUndo->SetInsertRange( *pUndoPam, false );
+            pUndo->SetInsertRange(*pUndoPam, true);
             // UGLY: temp. enable undo
             mxDoc->GetIDocumentUndoRedo().DoUndo(true);
             mxDoc->GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) );

Reply via email to