From c8e64ea4fd0122dad9d4f06bacffd1c179e753f8 Mon Sep 17 00:00:00 2001 From: Vasily Melenchuk Date: Fri, 2 Aug 2019 12:02:07 +0300 Subject: 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 Reviewed-by: Michael Stahl --- sw/source/core/inc/UndoAttribute.hxx | 1 + sw/source/core/undo/unattr.cxx | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'sw/source') 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 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(); -- cgit