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 fcd4222d36)

Change-Id: Ib419b29da552cf1df7150178924c45e3743cd7d9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180947
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Tested-by: Jenkins
This commit is contained in:
Michael Stahl
2025-01-30 16:33:04 +01:00
parent ff16c4e3f2
commit 3bbbe366e4
3 changed files with 41 additions and 9 deletions
+41
View File
@@ -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–)
@@ -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();
-4
View File
@@ -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