summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2019-08-02 12:02:07 +0300
committerMichael Stahl <Michael.Stahl@cib.de>2019-08-14 17:42:52 +0200
commitf9c85a92fae87c4c6d12bb1eab091ceb24cf8ca6 (patch)
tree53d6258cac1f794760433bce0a47522a59b4ed3e
parent488979e8aea3acaefe84d5e86e481751eb176749 (diff)
sw: avoid dangling references to style in undo/redo
if text style was created/deleted, reference contained in SwUndoAttr is irrelevant and can't be used. Instead of this style name is keept and reference to style is found during redo. Change-Id: I688ae5e7d58149f9fe824c6b0945e72aba82abb1 Reviewed-on: https://gerrit.libreoffice.org/76842 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Reviewed-by: Michael Stahl <Michael.Stahl@cib.de> (cherry picked from commit c8e64ea4fd0122dad9d4f06bacffd1c179e753f8) Reviewed-on: https://gerrit.libreoffice.org/77424
-rw-r--r--sw/source/core/inc/UndoAttribute.hxx1
-rw-r--r--sw/source/core/undo/unattr.cxx28
2 files changed, 29 insertions, 0 deletions
diff --git a/sw/source/core/inc/UndoAttribute.hxx b/sw/source/core/inc/UndoAttribute.hxx
index ab66b6d234c6..288eabe20765 100644
--- a/sw/source/core/inc/UndoAttribute.hxx
+++ b/sw/source/core/inc/UndoAttribute.hxx
@@ -42,6 +42,7 @@ class SwUndoAttr : public SwUndo, private SwUndRng
std::unique_ptr<SwRedlineSaveDatas> m_pRedlineSaveData;
sal_uLong m_nNodeIndex; // Offset: for Redlining
const SetAttrMode m_nInsertFlags; // insert flags
+ OUString m_aChrFormatName;
void RemoveIdx( SwDoc& rDoc );
diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx
index e389d4341dab..a8245c7a45bc 100644
--- a/sw/source/core/undo/unattr.cxx
+++ b/sw/source/core/undo/unattr.cxx
@@ -678,6 +678,15 @@ SwUndoAttr::SwUndoAttr( const SwPaM& rRange, const SfxPoolItem& rAttr,
, m_nInsertFlags( nFlags )
{
m_AttrSet.Put( rAttr );
+
+ // Save character style as a style name, not as a reference
+ const SfxPoolItem* pItem = m_AttrSet.GetItem(RES_TXTATR_CHARFMT);
+ if (pItem)
+ {
+ uno::Any aValue;
+ pItem->QueryValue(aValue, RES_TXTATR_CHARFMT);
+ aValue >>= m_aChrFormatName;
+ }
}
SwUndoAttr::SwUndoAttr( const SwPaM& rRange, const SfxItemSet& rSet,
@@ -688,6 +697,14 @@ SwUndoAttr::SwUndoAttr( const SwPaM& rRange, const SfxItemSet& rSet,
, m_nNodeIndex( ULONG_MAX )
, m_nInsertFlags( nFlags )
{
+ // Save character style as a style name, not as a reference
+ const SfxPoolItem* pItem = m_AttrSet.GetItem(RES_TXTATR_CHARFMT);
+ if (pItem)
+ {
+ uno::Any aValue;
+ pItem->QueryValue(aValue, RES_TXTATR_CHARFMT);
+ aValue >>= m_aChrFormatName;
+ }
}
SwUndoAttr::~SwUndoAttr()
@@ -771,6 +788,17 @@ void SwUndoAttr::RedoImpl(::sw::UndoRedoContext & rContext)
SwDoc & rDoc = rContext.GetDoc();
SwPaM & rPam = AddUndoRedoPaM(rContext);
+ // Restore pointer to char format from name
+ if (!m_aChrFormatName.isEmpty())
+ {
+ SwCharFormat* pCharFormat = rDoc.FindCharFormatByName(m_aChrFormatName);
+ if (pCharFormat)
+ {
+ SwFormatCharFormat aFormat(pCharFormat);
+ m_AttrSet.Put(aFormat);
+ }
+ }
+
if ( m_pRedlineData.get() &&
IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ) ) {
RedlineFlags eOld = rDoc.getIDocumentRedlineAccess().GetRedlineFlags();