sw: fix crash due to redlines on tables on ooo121112-2.docx

Problem is that after import there are SwRangeRedline that start in the
first cell of a table and end in the paragraph following the table.

There are <w:del> elements covering every individual paragraph in the
table; all of these are merged into one SwRangeRedline.

This could possibly be fixed in writerfilter by buffering the
m_pParaMarkerRedline until after convertToTable() to prevent the
merging, but perhaps it's better to fix it in SwXText::convertToTable().

Change-Id: I853ae624fffedb59a48bd90decb0973bf33beb68
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 208aefc..fe562d5 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -1172,12 +1172,40 @@ const SwTable* SwDoc::TextToTable( const std::vector< std::vector<SwNodeRange> >
            ++aRg.aEnd;
    }

    assert(aRg.aEnd == pEnd->nNode);
    assert(aRg.aStart == pStt->nNode);
    if( aRg.aEnd.GetIndex() == aRg.aStart.GetIndex() )
    {
        OSL_FAIL( "empty range" );
        ++aRg.aEnd;
    }


    {
        // TODO: this is not Undo-able - only good enough for file import
        IDocumentRedlineAccess & rIDRA(getIDocumentRedlineAccess());
        SwNodeIndex const prev(rTableNodes.begin()->begin()->aStart, -1);
        SwNodeIndex const* pPrev(&prev);
        // pPrev could point to non-textnode now
        for (auto row = rTableNodes.begin(); row != rTableNodes.end(); ++row)
        {
            for (auto cell = row->begin(); cell != row->end(); ++cell)
            {
                assert(SwNodeIndex(*pPrev, +1) == cell->aStart);
                SwPaM pam(cell->aStart, 0, *pPrev,
                        (pPrev->GetNode().IsCntntNode())
                            ? pPrev->GetNode().GetCntntNode()->Len() : 0);
                rIDRA.SplitRedline(pam);
                pPrev = &cell->aEnd;
            }
        }
        // another one to break between last cell and node after table
        SwPaM pam(SwNodeIndex(*pPrev, +1), 0, *pPrev,
                    (pPrev->GetNode().IsCntntNode())
                        ? pPrev->GetNode().GetCntntNode()->Len() : 0);
        rIDRA.SplitRedline(pam);
    }

    // We always use Upper to insert the Table
    SwNode2Layout aNode2Layout( aRg.aStart.GetNode() );

diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 04bc9a2..d21a6f2 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -2218,6 +2218,13 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
        throw  uno::RuntimeException();
    }

    IDocumentRedlineAccess & rIDRA(m_pImpl->m_pDoc->getIDocumentRedlineAccess());
    if (!IDocumentRedlineAccess::IsShowChanges(rIDRA.GetRedlineMode()))
    {
        throw uno::RuntimeException(
            "cannot convertToTable if tracked changes are hidden!");
    }

    //at first collect the text ranges as SwPaMs
    const uno::Sequence< uno::Sequence< uno::Reference< text::XTextRange > > >*
        pTableRanges = rTableRanges.getConstArray();