sw/source/core/doc/DocumentRedlineManager.cxx |   13 +++++++++----
 sw/source/core/docnode/ndtbl.cxx              |   11 ++++++++++-
 2 files changed, 19 insertions(+), 5 deletions(-)

New commits:
commit cd20d9512aa4f9fbe39fce48b3c49cdb13cca6e6
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Jul 19 15:58:36 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Jul 19 20:03:59 2023 +0200

    tdf#153115 sw: SwDoc::TextToTable(), first remove all redlines
    
    The problem is that there are redlines that overlap the created table
    cell nodes.
    
    For the writerfilter-import-API TextToTable() that was solved by
    splitting the redlines, but that would take a lot of effort here as it's
    not known ahead of time where the cells start and end, so just get rid
    of the redlines.
    
    Another issue is that the temporary SwPaM in
    DocumentRedlineManager::AcceptRedline() caused ~SwIndexReg() assert.
    
    (reportedly regression from commit 471212d464f54054f7419ef1890267d0def852d9)
    
    Change-Id: I6b211b6c8e5c7e4bdab1dac858707d7d7fd85029
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154655
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx 
b/sw/source/core/doc/DocumentRedlineManager.cxx
index d9148ce723f3..efed70b44a1a 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -2947,17 +2947,22 @@ bool DocumentRedlineManager::AcceptRedline( const 
SwPaM& rPam, bool bCallDelete
     // The Selection is only in the ContentSection. If there are Redlines
     // to Non-ContentNodes before or after that, then the Selections
     // expand to them.
-    SwPaM aPam( *rPam.GetMark(), *rPam.GetPoint() );
-    lcl_AdjustRedlineRange( aPam );
+    std::shared_ptr<SwUnoCursor> const 
pPam(m_rDoc.CreateUnoCursor(*rPam.GetPoint(), false));
+    if (rPam.HasMark())
+    {
+        pPam->SetMark();
+        *pPam->GetMark() = *rPam.GetMark();
+    }
+    lcl_AdjustRedlineRange(*pPam);
 
     if (m_rDoc.GetIDocumentUndoRedo().DoesUndo())
     {
         m_rDoc.GetIDocumentUndoRedo().StartUndo( SwUndoId::ACCEPT_REDLINE, 
nullptr );
-        m_rDoc.GetIDocumentUndoRedo().AppendUndo( 
std::make_unique<SwUndoAcceptRedline>( aPam ));
+        
m_rDoc.GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoAcceptRedline>(*pPam));
     }
 
     int nRet = lcl_AcceptRejectRedl( lcl_AcceptRedline, maRedlineTable,
-                                     bCallDelete, aPam );
+                                     bCallDelete, *pPam );
     if( nRet > 0 )
     {
         CompressRedlines();
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index cd6358ea0ecf..42c62bc9f802 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -635,6 +635,16 @@ const SwTable* SwDoc::TextToTable( const 
SwInsertTableOptions& rInsTableOpts,
                 return nullptr;
     }
 
+    if (GetIDocumentUndoRedo().DoesUndo())
+    {
+        GetIDocumentUndoRedo().StartUndo(SwUndoId::TEXTTOTABLE, nullptr);
+    }
+
+    // tdf#153115 first, remove all redlines; splitting them at cell boundaries
+    // would be tricky to implement, and it's unclear what the value of
+    // existing redlines is once it's been converted to a table
+    getIDocumentRedlineAccess().AcceptRedline(rRange, true);
+
     // Save first node in the selection if it is a context node
     SwContentNode * pSttContentNd = pStt->GetNode().GetContentNode();
 
@@ -645,7 +655,6 @@ const SwTable* SwDoc::TextToTable( const 
SwInsertTableOptions& rInsTableOpts,
     SwUndoTextToTable* pUndo = nullptr;
     if( GetIDocumentUndoRedo().DoesUndo() )
     {
-        GetIDocumentUndoRedo().StartUndo( SwUndoId::TEXTTOTABLE, nullptr );
         pUndo = new SwUndoTextToTable( aOriginal, rInsTableOpts, cCh,
                     o3tl::narrowing<sal_uInt16>(eAdjust), pTAFormat );
         GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) );

Reply via email to