sw/qa/extras/uiwriter/uiwriter9.cxx | 74 ++++++++++++++++ sw/source/core/doc/DocumentContentOperationsManager.cxx | 11 -- sw/source/core/undo/untblk.cxx | 4 3 files changed, 78 insertions(+), 11 deletions(-)
New commits: commit 3227660e55416254463234f35a43268b9b4c2c9e Author: Michael Stahl <[email protected]> AuthorDate: Thu Jan 30 15:06:34 2025 +0100 Commit: Michael Stahl <[email protected]> CommitDate: Thu Jan 30 16:33:13 2025 +0100 (tdf#159377 related) sw: fix undo of table pasted in middle of paragraph The problem is that the !bCanMoveBack path doesn't work if the insert position's content index isn't 0. (regression from commit fcd4222d36e1864452163e5c94976eea353bbaf0) Change-Id: I746db2187ab8f2e24eb694dc94d7eea9f50e2d9f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180948 Tested-by: Jenkins Reviewed-by: Michael Stahl <[email protected]> diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx b/sw/qa/extras/uiwriter/uiwriter9.cxx index d643e723afc5..559cd7619188 100644 --- a/sw/qa/extras/uiwriter/uiwriter9.cxx +++ b/sw/qa/extras/uiwriter/uiwriter9.cxx @@ -159,6 +159,39 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159377) CPPUNIT_ASSERT_EQUAL(SwNodeOffset(28), pDoc->GetNodes().Count()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testPasteTableInMiddleOfParagraph) +{ + createSwDoc(); + + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + + SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0); + pWrtShell->InsertTable(aTableOptions, /*nRows=*/2, /*nCols=*/2); + pWrtShell->MoveTable(GotoPrevTable, fnTableStart); + + dispatchCommand(mxComponent, u".uno:SelectTable"_ustr, {}); + dispatchCommand(mxComponent, u".uno:Copy"_ustr, {}); + + pWrtShell->Undo(); + + pWrtShell->Insert(u"AB"_ustr); + + pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false); + + dispatchCommand(mxComponent, u".uno:Paste"_ustr, {}); + + pWrtShell->Undo(); + + // the problem was that the A was missing + CPPUNIT_ASSERT_EQUAL(OUString("AB"), + pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText()); + + pWrtShell->Redo(); + pWrtShell->Undo(); + CPPUNIT_ASSERT_EQUAL(OUString("AB"), + pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf111969) { // given a document with a field surrounded by N-dashes (–date–) diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 4fa8f85f3da6..252e42588121 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -5153,7 +5153,9 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo // Note this doesn't just check IsStartNode() because SwDoc::AppendDoc() // intentionally sets it to the body start node, perhaps it should just // call SplitNode instead? - if (!pStart->GetNode().IsSectionNode() && !pStart->GetNode().IsTableNode()) + if ((!pStart->GetNode().IsSectionNode() && !pStart->GetNode().IsTableNode()) + || (pCopyPam->GetPoint()->GetContentIndex() != 0 // also if node will split + && pCopyPam->GetPoint()->GetContentIndex() != pCopyPam->GetPoint()->GetNode().GetContentNode()->Len())) { bCanMoveBack = pCopyPam->Move(fnMoveBackward, GoInContent); } @@ -5347,7 +5349,7 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo --aRg.aEnd; } } - assert(!bCanMoveBack); + assert((nDeleteTextNodes.get() != 0) == bCanMoveBack); } pDestTextNd = aInsPos.GetNode().GetTextNode(); commit 3bbbe366e455f1b165f2f913fffd27f3a0e03a2d Author: Michael Stahl <[email protected]> AuthorDate: Thu Jan 30 14:47:01 2025 +0100 Commit: Michael Stahl <[email protected]> CommitDate: Thu Jan 30 16:33:04 2025 +0100 tdf#159377 sw: fix undo of paste table into footnote Tables aren't allowed in footnotes, hence pasting a table into a footnote will paste only the text nodes in the cells but not the table nodes. This code isn't prepared for this situation, so the adjustment of the position doesn't happen. if (pCopyPam->GetPoint()->GetNode().IsStartNode()) pCopyPam->GetPoint()->Adjust(SwNodeOffset(-1)); But then the corresponding adjustment in SwUndoInserts::SetInsertRange() does happen and the stored start node index is wrong. It looks like both of these adjustments can simply be removed. (regression from commit fcd4222d36e1864452163e5c94976eea353bbaf0) Change-Id: Ib419b29da552cf1df7150178924c45e3743cd7d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180947 Reviewed-by: Michael Stahl <[email protected]> Tested-by: Jenkins diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx b/sw/qa/extras/uiwriter/uiwriter9.cxx index 666f3aefe5dc..d643e723afc5 100644 --- a/sw/qa/extras/uiwriter/uiwriter9.cxx +++ b/sw/qa/extras/uiwriter/uiwriter9.cxx @@ -118,6 +118,47 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf158785) CPPUNIT_ASSERT_EQUAL(IsAttrAtPos::NONE, aContentAtPos.eContentAtPos); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159377) +{ + createSwDoc(); + + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + + SwInsertTableOptions aTableOptions(SwInsertTableFlags::DefaultBorder, 0); + pWrtShell->InsertTable(aTableOptions, /*nRows=*/2, /*nCols=*/2); + pWrtShell->MoveTable(GotoPrevTable, fnTableStart); + + dispatchCommand(mxComponent, u".uno:SelectTable"_ustr, {}); + dispatchCommand(mxComponent, u".uno:Copy"_ustr, {}); + + pWrtShell->InsertFootnote(u""_ustr); + CPPUNIT_ASSERT(pWrtShell->IsCursorInFootnote()); + + CPPUNIT_ASSERT_EQUAL(SwNodeOffset(28), pDoc->GetNodes().Count()); + + dispatchCommand(mxComponent, u".uno:Paste"_ustr, {}); + + // this pasted the 4 text nodes in the table, but no table nodes + // as currently tables aren't allowed in footnotes + + CPPUNIT_ASSERT_EQUAL(SwNodeOffset(32), pDoc->GetNodes().Count()); + + pWrtShell->Undo(); + + CPPUNIT_ASSERT(pWrtShell->IsCursorInFootnote()); + // problem was that this was 29 with an extra text node in the footnote + CPPUNIT_ASSERT_EQUAL(SwNodeOffset(28), pDoc->GetNodes().Count()); + + pWrtShell->Redo(); + + CPPUNIT_ASSERT_EQUAL(SwNodeOffset(32), pDoc->GetNodes().Count()); + + pWrtShell->Undo(); + + CPPUNIT_ASSERT_EQUAL(SwNodeOffset(28), pDoc->GetNodes().Count()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf111969) { // given a document with a field surrounded by N-dashes (–date–) diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index c2eca8469588..4fa8f85f3da6 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -5552,11 +5552,6 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo { // Reset the offset to 0 as it was before the insertion pCopyPam->GetPoint()->Adjust(SwNodeOffset(+1)); - - // If the next node is a start node, then step back: SetInsertRange() - // will add 1 in this case, but that is too much... - if (pCopyPam->GetPoint()->GetNode().IsStartNode()) - pCopyPam->GetPoint()->Adjust(SwNodeOffset(-1)); } oInsContentIndex.reset(); pCopyPam->Exchange(); diff --git a/sw/source/core/undo/untblk.cxx b/sw/source/core/undo/untblk.cxx index 55ae66b86fd9..8c5288aed0bd 100644 --- a/sw/source/core/undo/untblk.cxx +++ b/sw/source/core/undo/untblk.cxx @@ -129,10 +129,6 @@ void SwUndoInserts::SetInsertRange( const SwPaM& rPam, bool bScanFlys, m_nSttContent = pTmpPos->GetContentIndex(); m_nDeleteTextNodes = nDeleteTextNodes; - if (m_nDeleteTextNodes == SwNodeOffset(0)) // if a table selection is added... - { - ++m_nSttNode; // ... then the CopyPam is not fully correct - } } // Fill m_FlyUndos with flys anchored to first and last paragraphs
