sw/qa/extras/uiwriter/uiwriter9.cxx | 33 ++++++++++++++++ sw/source/core/doc/DocumentContentOperationsManager.cxx | 6 +- 2 files changed, 37 insertions(+), 2 deletions(-)
New commits: commit d7a0bc8c8d2d2e4fa4c6e2e29e2de09ea9bb56a6 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Thu Jan 30 15:06:34 2025 +0100 Commit: Adolfo Jayme Barrientos <fit...@ubuntu.com> CommitDate: Fri Jan 31 11:35:57 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 <michael.st...@allotropia.de> (cherry picked from commit 3227660e55416254463234f35a43268b9b4c2c9e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180964 Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com> diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx b/sw/qa/extras/uiwriter/uiwriter9.cxx index 30cdcb7934f8..c0eeae073c39 100644 --- a/sw/qa/extras/uiwriter/uiwriter9.cxx +++ b/sw/qa/extras/uiwriter/uiwriter9.cxx @@ -158,6 +158,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 165f3d1b6e96..c795971c00e9 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -5085,7 +5085,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 (!pStt->GetNode().IsSectionNode() && !pStt->GetNode().IsTableNode()) + if ((!pStt->GetNode().IsSectionNode() && !pStt->GetNode().IsTableNode()) + || (pCopyPam->GetPoint()->GetContentIndex() != 0 // also if node will split + && pCopyPam->GetPoint()->GetContentIndex() != pCopyPam->GetPoint()->GetNode().GetContentNode()->Len())) { bCanMoveBack = pCopyPam->Move(fnMoveBackward, GoInContent); } @@ -5277,7 +5279,7 @@ bool DocumentContentOperationsManager::CopyImplImpl(SwPaM& rPam, SwPosition& rPo --aRg.aEnd; } } - assert(!bCanMoveBack); + assert((nDeleteTextNodes.get() != 0) == bCanMoveBack); } pDestTextNd = aInsPos.GetNode().GetTextNode();