summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-12-17 19:48:22 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2021-01-15 18:21:25 +0100
commitb1ee85d5c19466fb65d934491639fd4f2769fe13 (patch)
tree0af2ad33ba516ccc037305d88edd2d8ab6eb72e6 /sw
parentd01fb1a86ead0ce6441906838878835b299a3dfb (diff)
tdf#138897 sw: avoid creating SwUndoResetAttr in CopyImplImpl()
The problem is that SwTextNode::CopyCollFormat() both creates the SwTextFormatColl with undo and applies it with undo. The first is desirable, the second causes a problem because it necessarily happens after SplitNode() and currently happens before copying the non-start/end nodes, so the node-index may not match in Undo, regardless if it runs before or after SwUndoCpyDoc. But SwUndoInserts restores the SwTextFormatColl on the node itself, so it can just be suppressed, which looks easier than refactoring this to call SplitNode() with Undo enabled. (regression from b4365b985178e1866c74afd757a104aad1d405a9) Change-Id: I4d15fb88cd5ae4cc53d9afb3397dec8fcf7635fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107921 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109329
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/ndtxt.hxx2
-rw-r--r--sw/qa/extras/uiwriter/data3/tdf100018-1.odtbin0 -> 18795 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter3.cxx15
-rw-r--r--sw/source/core/doc/DocumentContentOperationsManager.cxx6
-rw-r--r--sw/source/core/docnode/ndcopy.cxx18
5 files changed, 36 insertions, 5 deletions
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index b222b6568ed2..f6605d73c247 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -412,7 +412,7 @@ public:
/** Copy collection with all auto formats to dest-node.
The latter might be in another document!
(Method in ndcopy.cxx!!). */
- void CopyCollFormat( SwTextNode& rDestNd );
+ void CopyCollFormat(SwTextNode& rDestNd, bool bUndoForChgFormatColl = true);
// BEGIN OF BULLET/NUMBERING/OUTLINE STUFF:
diff --git a/sw/qa/extras/uiwriter/data3/tdf100018-1.odt b/sw/qa/extras/uiwriter/data3/tdf100018-1.odt
new file mode 100644
index 000000000000..5cd36efcee77
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data3/tdf100018-1.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index c62b5b03c99d..e568e695000a 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -2069,4 +2069,19 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf137964)
CPPUNIT_ASSERT_EQUAL(sal_Int32(3090), xShape->getPosition().Y);
}
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf138897)
+{
+ load(DATA_DIRECTORY, "tdf100018-1.odt");
+
+ dispatchCommand(mxComponent, ".uno:SelectAll", {});
+ dispatchCommand(mxComponent, ".uno:Cut", {});
+ dispatchCommand(mxComponent, ".uno:Paste", {});
+ // this was crashing
+ dispatchCommand(mxComponent, ".uno:Undo", {});
+ dispatchCommand(mxComponent, ".uno:Redo", {});
+ dispatchCommand(mxComponent, ".uno:Undo", {});
+ dispatchCommand(mxComponent, ".uno:Redo", {});
+ Scheduler::ProcessEventsToIdle();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 9329356eea7c..aefd7feb881e 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -4887,7 +4887,8 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
{
if (bCopyCollFormat)
{
- pSttTextNd->CopyCollFormat( *pDestTextNd );
+ // tdf#138897 no Undo for applying style, SwUndoInserts does it
+ pSttTextNd->CopyCollFormat(*pDestTextNd, false);
POP_NUMRULE_STATE
}
@@ -4986,7 +4987,8 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo
// Also copy all format templates
if( bCopyCollFormat && ( bOneNode || bEmptyDestNd ))
{
- pEndTextNd->CopyCollFormat( *pDestTextNd );
+ // tdf#138897 no Undo for applying style, SwUndoInserts does it
+ pEndTextNd->CopyCollFormat(*pDestTextNd, false);
if ( bOneNode )
{
POP_NUMRULE_STATE
diff --git a/sw/source/core/docnode/ndcopy.cxx b/sw/source/core/docnode/ndcopy.cxx
index 37fe854f88c4..d98123b0111c 100644
--- a/sw/source/core/docnode/ndcopy.cxx
+++ b/sw/source/core/docnode/ndcopy.cxx
@@ -18,6 +18,7 @@
*/
#include <doc.hxx>
#include <IDocumentFieldsAccess.hxx>
+#include <IDocumentUndoRedo.hxx>
#include <node.hxx>
#include <frmfmt.hxx>
#include <swtable.hxx>
@@ -331,7 +332,7 @@ SwTableNode* SwTableNode::MakeCopy( SwDoc& rDoc, const SwNodeIndex& rIdx ) const
return pTableNd;
}
-void SwTextNode::CopyCollFormat( SwTextNode& rDestNd )
+void SwTextNode::CopyCollFormat(SwTextNode& rDestNd, bool const bUndoForChgFormatColl)
{
// Copy the formats into the other document:
// Special case for PageBreak/PageDesc/ColBrk
@@ -351,10 +352,23 @@ void SwTextNode::CopyCollFormat( SwTextNode& rDestNd )
aPgBrkSet.Put( *pAttr );
}
- rDestNd.ChgFormatColl( rDestDoc.CopyTextColl( *GetTextColl() ));
+ // this may create undo action SwUndoFormatCreate
+ auto const pCopy( rDestDoc.CopyTextColl( *GetTextColl() ) );
+ if (bUndoForChgFormatColl)
+ {
+ rDestNd.ChgFormatColl(pCopy);
+ }
+ else // tdf#138897
+ {
+ ::sw::UndoGuard const ug(rDestDoc.GetIDocumentUndoRedo());
+ rDestNd.ChgFormatColl(pCopy);
+ }
pSet = GetpSwAttrSet();
if( nullptr != pSet )
+ {
+ // note: this may create undo actions but not for setting the items
pSet->CopyToModify( rDestNd );
+ }
if( aPgBrkSet.Count() )
rDestNd.SetAttr( aPgBrkSet );