sw/source/core/doc/DocumentRedlineManager.cxx |   13 +++++---
 sw/source/core/docnode/ndtbl.cxx              |   11 ++++++
 sw/source/core/unocore/unoobj2.cxx            |   42 +++++++++++++++++++-------
 3 files changed, 50 insertions(+), 16 deletions(-)

New commits:
commit be59be4cc602683605dc26b08dba59de8c29b16d
Author:     Michael Stahl <[email protected]>
AuthorDate: Wed Jul 19 15:58:36 2023 +0200
Commit:     Andras Timar <[email protected]>
CommitDate: Mon Jul 31 23:21:17 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 <[email protected]>
    (cherry picked from commit cd20d9512aa4f9fbe39fce48b3c49cdb13cca6e6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154621
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx 
b/sw/source/core/doc/DocumentRedlineManager.cxx
index 60ddf9d62151..1d0e2b561859 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -2903,17 +2903,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 8b8e1b6af15e..a9d8494bf442 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) );
commit e2a2d3560c836e16858a19c82f7153c5a4e7b06c
Author:     Michael Stahl <[email protected]>
AuthorDate: Fri Jul 28 17:33:20 2023 +0200
Commit:     Andras Timar <[email protected]>
CommitDate: Mon Jul 31 23:21:16 2023 +0200

    tdf#149555 sw: convert RANGE_IS_SECTION SwXTextRange if possible
    
    The writerfilter import got an exception in
    SectionPropertyMap::CloseSectionGroup() because XTextRangeToSwPaM()
    can't handle RANGE_IS_SECTION SwXTextRange.
    
    (regression from commit 7ab349296dac79dad3fec09f60348efcbb9ea17e)
    
    Change-Id: I38b37fdec64f4699c0fa1a090c72a8676ff386a6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155026
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit 0f39ecfed57f3f32d4f5cadf50b7dd9de77f8d7e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154969
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sw/source/core/unocore/unoobj2.cxx 
b/sw/source/core/unocore/unoobj2.cxx
index f1c5a7e3675a..4eb527c5111e 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -1064,20 +1064,40 @@ void SAL_CALL SwXTextRange::setString(const OUString& 
rString)
 
 bool SwXTextRange::GetPositions(SwPaM& rToFill, ::sw::TextRangeMode const 
eMode) const
 {
-    if (RANGE_IS_SECTION == m_pImpl->m_eRangePosition
-        && eMode == ::sw::TextRangeMode::AllowNonTextNode)
+    if (RANGE_IS_SECTION == m_pImpl->m_eRangePosition)
     {
         if (auto const pSectFormat = static_cast<SwSectionFormat 
const*>(m_pImpl->m_pTableOrSectionFormat))
         {
-            SwNodeIndex const*const 
pSectionNode(pSectFormat->GetContent().GetContentIdx());
-            assert(pSectionNode);
-            assert(pSectionNode->GetNodes().IsDocNodes());
-            rToFill.GetPoint()->Assign( pSectionNode->GetNode(), 
SwNodeOffset(1) );
-            rToFill.SetMark();
-            rToFill.GetMark()->Assign( 
*pSectionNode->GetNode().EndOfSectionNode(), SwNodeOffset(-1) );
-            if (const SwContentNode* pCNd = 
rToFill.GetMark()->GetContentNode())
-                rToFill.GetMark()->AssignEndIndex(*pCNd);
-            return true;
+            if (eMode == ::sw::TextRangeMode::AllowNonTextNode)
+            {
+                SwNodeIndex const*const 
pSectionNode(pSectFormat->GetContent().GetContentIdx());
+                assert(pSectionNode);
+                assert(pSectionNode->GetNodes().IsDocNodes());
+                rToFill.GetPoint()->Assign( pSectionNode->GetNode(), 
SwNodeOffset(1) );
+                rToFill.SetMark();
+                rToFill.GetMark()->Assign( 
*pSectionNode->GetNode().EndOfSectionNode(), SwNodeOffset(-1) );
+                if (const SwContentNode* pCNd = 
rToFill.GetMark()->GetContentNode())
+                    rToFill.GetMark()->AssignEndIndex(*pCNd);
+                return true;
+            }
+            else
+            {
+                SwPaM aPaM(*pSectFormat->GetContent().GetContentIdx());
+                aPaM.Move(fnMoveForward, GoInContent);
+                assert(aPaM.GetPoint()->GetNode() < 
*pSectFormat->GetContent().GetContentIdx()->GetNode().EndOfSectionNode());
+                aPaM.SetMark();
+                *aPaM.GetPoint() = 
SwPosition(*pSectFormat->GetContent().GetContentIdx()->GetNode().EndOfSectionNode());
+                aPaM.Move(fnMoveBackward, GoInContent);
+                assert(*pSectFormat->GetContent().GetContentIdx() < 
aPaM.GetPoint()->GetNode());
+                // tdf#149555 if there is no table involved, only nested
+                // sections, then PaM is valid
+                if (aPaM.GetPoint()->GetNode().FindTableNode()
+                    == aPaM.GetMark()->GetNode().FindTableNode())
+                {
+                    rToFill = aPaM;
+                    return true;
+                }
+            }
         }
     }
     ::sw::mark::IMark const * const pBkmk = m_pImpl->GetBookmark();

Reply via email to