sw/source/core/doc/DocumentRedlineManager.cxx | 66 ++++++++++++-------------- sw/source/core/inc/DocumentRedlineManager.hxx | 1 2 files changed, 31 insertions(+), 36 deletions(-)
New commits: commit a562be54f3127f4e22a3a38e62db2b38d48499f3 Author: Michael Stahl <mst...@redhat.com> Date: Fri Sep 15 13:51:04 2017 +0200 ofz#3301 sw: DeleteAndJoin found yet another way to delete new redline Not only can that happen in CompressRedlines(), it can also happen in the SwComparePosition::Outside case when the DeleteRedline() decides in particular circumstances to split up the inserted new redline. Arguably it's wrong to split up the new redline in this case; not sure if that ever happens in a legitimate use case though. Avoid this by removing the hack to temporarily insert the new redline and instead create a temporary SwUnoCursor that will be corrected on behalf of the new redline, while the new redline is parked on a safe node. This not only avoids the crash on this file but also makes the "corrupted redline table" assertions go away. Change-Id: I478f4cfc53a19d2cf2f0937f631962f80b1815ff Reviewed-on: https://gerrit.libreoffice.org/42408 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx index f2d51192759d..c5da74836240 100644 --- a/sw/source/core/doc/DocumentRedlineManager.cxx +++ b/sw/source/core/doc/DocumentRedlineManager.cxx @@ -27,6 +27,7 @@ #include <docary.hxx> #include <ndtxt.hxx> #include <comcore.hrc> +#include <unocrsr.hxx> #include <swmodule.hxx> #include <editsh.hxx> #include <vcl/layout.hxx> @@ -575,6 +576,32 @@ namespace } } } + + /// in case some text is deleted, ensure that the not-yet-inserted + /// SwRangeRedline has its positions corrected not to point to deleted node + class TemporaryRedlineUpdater + { + private: + SwRangeRedline & m_rRedline; + std::shared_ptr<SwUnoCursor> m_pCursor; + public: + TemporaryRedlineUpdater(SwDoc & rDoc, SwRangeRedline & rRedline) + : m_rRedline(rRedline) + , m_pCursor(rDoc.CreateUnoCursor(*rRedline.GetPoint(), false)) + { + if (m_rRedline.HasMark()) + { + m_pCursor->SetMark(); + *m_pCursor->GetMark() = *m_rRedline.GetMark(); + *m_rRedline.GetMark() = SwPosition(rDoc.GetNodes().GetEndOfContent()); + } + *m_rRedline.GetPoint() = SwPosition(rDoc.GetNodes().GetEndOfContent()); + } + ~TemporaryRedlineUpdater() + { + static_cast<SwPaM&>(m_rRedline) = *m_pCursor; + } + }; } namespace sw @@ -1223,19 +1250,11 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall { mpRedlineTable->Remove( n ); bDec = true; - // We insert temporarily so that pNew is - // also dealt with when moving the indices. if( bCallDelete ) { - ::comphelper::FlagGuard g(m_isForbidCompressRedlines); - mpRedlineTable->Insert( pNewRedl ); + TemporaryRedlineUpdater const u(m_rDoc, *pNewRedl); m_rDoc.getIDocumentContentOperations().DeleteAndJoin( *pRedl ); - if( !mpRedlineTable->Remove( pNewRedl ) ) - { - assert(false); // can't happen - pNewRedl = nullptr; - } - bCompress = true; // delayed compress + n = 0; // re-initialize } delete pRedl; } @@ -1257,17 +1276,8 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall if( bCallDelete ) { - // We insert temporarily so that pNew is - // also dealt with when moving the indices. - ::comphelper::FlagGuard g(m_isForbidCompressRedlines); - mpRedlineTable->Insert( pNewRedl ); + TemporaryRedlineUpdater const u(m_rDoc, *pNewRedl); m_rDoc.getIDocumentContentOperations().DeleteAndJoin( aPam ); - if( !mpRedlineTable->Remove( pNewRedl ) ) - { - assert(false); // can't happen - pNewRedl = nullptr; - } - bCompress = true; // delayed compress n = 0; // re-initialize } bDec = true; @@ -1288,17 +1298,8 @@ bool DocumentRedlineManager::AppendRedline( SwRangeRedline* pNewRedl, bool bCall if( bCallDelete ) { - // We insert temporarily so that pNew is - // also dealt with when moving the indices. - ::comphelper::FlagGuard g(m_isForbidCompressRedlines); - mpRedlineTable->Insert( pNewRedl ); + TemporaryRedlineUpdater const u(m_rDoc, *pNewRedl); m_rDoc.getIDocumentContentOperations().DeleteAndJoin( aPam ); - if( !mpRedlineTable->Remove( pNewRedl ) ) - { - assert(false); // can't happen - pNewRedl = nullptr; - } - bCompress = true; // delayed compress n = 0; // re-initialize bDec = true; } @@ -1793,11 +1794,6 @@ bool DocumentRedlineManager::AppendTableCellRedline( SwTableCellRedline* pNewRed void DocumentRedlineManager::CompressRedlines() { - if (m_isForbidCompressRedlines) - { - return; - } - CHECK_REDLINE( *this ) void (SwRangeRedline::*pFnc)(sal_uInt16, size_t) = nullptr; diff --git a/sw/source/core/inc/DocumentRedlineManager.hxx b/sw/source/core/inc/DocumentRedlineManager.hxx index 999cbd7137ce..bdcd45c5fc67 100644 --- a/sw/source/core/inc/DocumentRedlineManager.hxx +++ b/sw/source/core/inc/DocumentRedlineManager.hxx @@ -137,7 +137,6 @@ private: sal_uInt16 mnAutoFormatRedlnCommentNo; /**< SeqNo for conjoining of AutoFormat-Redlines. by the UI. Managed by SwAutoFormat! */ css::uno::Sequence <sal_Int8 > maRedlinePasswd; - bool m_isForbidCompressRedlines = false; }; }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits