summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2017-09-15 13:51:04 +0200
committerAndras Timar <andras.timar@collabora.com>2017-09-19 22:50:19 +0200
commit284193dbc07f4514af05d64d9cdf640a95158a78 (patch)
treee90f5cbd09f88aef1075b49d71ab25f5809cb60a
parente67e1e73958c013371d89699a6512e96962d7f52 (diff)
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 <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit a562be54f3127f4e22a3a38e62db2b38d48499f3)
-rw-r--r--sw/source/core/doc/DocumentRedlineManager.cxx66
-rw-r--r--sw/source/core/inc/DocumentRedlineManager.hxx1
2 files changed, 31 insertions, 36 deletions
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;
};
}