diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2019-08-02 12:02:07 +0300 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2019-08-13 00:46:56 +0200 |
commit | c8e64ea4fd0122dad9d4f06bacffd1c179e753f8 (patch) | |
tree | 6d22bc9b06bcfc6f208c554316236bb0a97d596f /sw/source | |
parent | 442431b1ef78431df33b6b6e308a689adc998f74 (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>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/inc/UndoAttribute.hxx | 1 | ||||
-rw-r--r-- | sw/source/core/undo/unattr.cxx | 28 |
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 ca1c30ddaebd..6660cdcd2c65 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(); |