sw/qa/extras/uiwriter/uiwriter6.cxx | 37 ++++++++++++++++++++++++++++++++++++ sw/source/core/docnode/ndcopy.cxx | 5 +++- 2 files changed, 41 insertions(+), 1 deletion(-)
New commits: commit ff5bf008a3737c68c899da667456f8995b064869 Author: Jim Raykowski <rayk...@gmail.com> AuthorDate: Sat Nov 19 21:54:11 2022 -0900 Commit: Jim Raykowski <rayk...@gmail.com> CommitDate: Tue Nov 22 23:12:53 2022 +0100 tdf#151828 fix table name changes on cut and paste Change-Id: Ibd9fc78d88732b63d418404fa23e1560bf531fbf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142984 Tested-by: Jenkins Tested-by: Heiko Tietze <heiko.tie...@documentfoundation.org> Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org> Reviewed-by: Jim Raykowski <rayk...@gmail.com> diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx b/sw/qa/extras/uiwriter/uiwriter6.cxx index ad883c5defe0..dc6db051974f 100644 --- a/sw/qa/extras/uiwriter/uiwriter6.cxx +++ b/sw/qa/extras/uiwriter/uiwriter6.cxx @@ -2259,6 +2259,43 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf151828_Comment2) CPPUNIT_ASSERT_EQUAL(OUString("Shape"), pObject->GetName()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf151828) +{ + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + // insert a table + SwInsertTableOptions TableOpt(SwInsertTableFlags::DefaultBorder, 0); + pWrtShell->InsertTable(TableOpt, 1, 1); + + // move cursor into the table + CPPUNIT_ASSERT(pWrtShell->MoveTable(GotoPrevTable, fnTableStart)); + + SwFrameFormat* pFormat = pWrtShell->GetTableFormat(); + CPPUNIT_ASSERT(pFormat); + + // set name of table to 'MyTableName' + pWrtShell->SetTableName(*pFormat, "MyTableName"); + + // cut and paste the table + dispatchCommand(mxComponent, ".uno:SelectTable", {}); + Scheduler::ProcessEventsToIdle(); + dispatchCommand(mxComponent, ".uno:Cut", {}); + Scheduler::ProcessEventsToIdle(); + dispatchCommand(mxComponent, ".uno:Paste", {}); + Scheduler::ProcessEventsToIdle(); + + // move cursor into the pasted table + CPPUNIT_ASSERT(pWrtShell->MoveTable(GotoPrevTable, fnTableStart)); + + pFormat = pWrtShell->GetTableFormat(); + CPPUNIT_ASSERT(pFormat); + + // Before the fix the pasted table name was 'Table1'. + CPPUNIT_ASSERT_EQUAL(OUString("MyTableName"), pFormat->GetName()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/docnode/ndcopy.cxx b/sw/source/core/docnode/ndcopy.cxx index b5383174336d..1f27421ad618 100644 --- a/sw/source/core/docnode/ndcopy.cxx +++ b/sw/source/core/docnode/ndcopy.cxx @@ -258,11 +258,14 @@ SwTableNode* SwTableNode::MakeCopy( SwDoc& rDoc, const SwNodeIndex& rIdx ) const { const SwFrameFormats& rTableFormats = *rDoc.GetTableFrameFormats(); for( size_t n = rTableFormats.size(); n; ) - if( rTableFormats[ --n ]->GetName() == sTableName ) + { + const SwFrameFormat* pFormat = rTableFormats[--n]; + if (pFormat->GetName() == sTableName && rDoc.IsUsed(*pFormat)) { sTableName = rDoc.GetUniqueTableName(); break; } + } } SwFrameFormat* pTableFormat = rDoc.MakeTableFrameFormat( sTableName, rDoc.GetDfltFrameFormat() );