sw/inc/pagedesc.hxx | 1 + sw/qa/core/undo/undo.cxx | 23 +++++++++++++++++++++++ sw/source/core/layout/pagedesc.cxx | 5 +++++ sw/source/core/undo/SwUndoPageDesc.cxx | 8 ++++++-- 4 files changed, 35 insertions(+), 2 deletions(-)
New commits: commit 434cf190c7dcf0e8b99d473eaff2acfd70b6e82e Author: David Hashe <[email protected]> AuthorDate: Sun Oct 5 21:20:48 2025 -0400 Commit: Noel Grandin <[email protected]> CommitDate: Tue Oct 7 08:19:19 2025 +0200 tdf#148703 fix follow links for recreated page descs When the creation of a SwPageDesc is undone and then redone, and that page desc had itself as its own follow, then the follow link was not being set correctly. I noticed this when working on tdf#148703, and it is a small part of that fix that can be merged independently. Tested with: CPPUNIT_TEST_NAME="SwCoreUndoTest testPageDescThatFollowsItself" make CppunitTest_sw_core_undo Change-Id: I798197de78e32694a5819da9025fa84b44e30e98 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191979 Reviewed-by: Noel Grandin <[email protected]> Tested-by: Jenkins diff --git a/sw/inc/pagedesc.hxx b/sw/inc/pagedesc.hxx index 0113371b7de8..a9bfa1379269 100644 --- a/sw/inc/pagedesc.hxx +++ b/sw/inc/pagedesc.hxx @@ -395,6 +395,7 @@ public: SwPageDescExt & operator = (const SwPageDesc & rSrc); UIName const & GetName() const; + UIName const & GetFollowName() const; explicit operator SwPageDesc() const; // #i7983# }; diff --git a/sw/qa/core/undo/undo.cxx b/sw/qa/core/undo/undo.cxx index 3a4c86976bf9..094432d3f344 100644 --- a/sw/qa/core/undo/undo.cxx +++ b/sw/qa/core/undo/undo.cxx @@ -174,6 +174,29 @@ CPPUNIT_TEST_FIXTURE(SwCoreUndoTest, testAnchorTypeChangePosition) CPPUNIT_ASSERT_EQUAL(aOldPos, aNewPos); } +CPPUNIT_TEST_FIXTURE(SwCoreUndoTest, testPageDescThatFollowsItself) +{ + createSwDoc(); + + SwDoc* pDoc = getSwDoc(); + + // Create a custom page desc that has its follow page desc set to itself + // (that happens by default). This means that, if the current page uses this + // page desc, then the next page will as well. + SwPageDesc* pOldPageDesc = pDoc->MakePageDesc(UIName("customPageDesc"), nullptr, true); + CPPUNIT_ASSERT(pOldPageDesc); + CPPUNIT_ASSERT_EQUAL(pOldPageDesc, pOldPageDesc->GetFollow()); + + dispatchCommand(mxComponent, u".uno:Undo"_ustr, {}); + dispatchCommand(mxComponent, u".uno:Redo"_ustr, {}); + + // Without the fix, the follow page desc no longer matches, and the next page + // would not use the correct page desc. + SwPageDesc* pNewPageDesc = pDoc->FindPageDesc(UIName("customPageDesc")); + CPPUNIT_ASSERT(pNewPageDesc); + CPPUNIT_ASSERT_EQUAL(pNewPageDesc, pNewPageDesc->GetFollow()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/pagedesc.cxx b/sw/source/core/layout/pagedesc.cxx index 780123d62452..2bb7059ffe22 100644 --- a/sw/source/core/layout/pagedesc.cxx +++ b/sw/source/core/layout/pagedesc.cxx @@ -770,6 +770,11 @@ UIName const & SwPageDescExt::GetName() const return m_PageDesc.GetName(); } +UIName const & SwPageDescExt::GetFollowName() const +{ + return m_sFollow; +} + void SwPageDescExt::SetPageDesc(const SwPageDesc & rPageDesc) { m_PageDesc = rPageDesc; diff --git a/sw/source/core/undo/SwUndoPageDesc.cxx b/sw/source/core/undo/SwUndoPageDesc.cxx index f61db8b38336..3df5d986c691 100644 --- a/sw/source/core/undo/SwUndoPageDesc.cxx +++ b/sw/source/core/undo/SwUndoPageDesc.cxx @@ -278,7 +278,9 @@ void SwUndoPageDescCreate::UndoImpl(::sw::UndoRedoContext &) void SwUndoPageDescCreate::DoImpl() { SwPageDesc aPageDesc(m_aNew); - m_rDoc.MakePageDesc(m_aNew.GetName(), &aPageDesc, false); + SwPageDesc* pNewPageDesc = m_rDoc.MakePageDesc(m_aNew.GetName(), &aPageDesc, false); + if (m_aNew.GetName() == m_aNew.GetFollowName()) + pNewPageDesc->SetFollow(pNewPageDesc); } void SwUndoPageDescCreate::RedoImpl(::sw::UndoRedoContext &) @@ -317,7 +319,9 @@ SwUndoPageDescDelete::~SwUndoPageDescDelete() void SwUndoPageDescDelete::UndoImpl(::sw::UndoRedoContext &) { SwPageDesc aPageDesc(m_aOld); - m_rDoc.MakePageDesc(m_aOld.GetName(), &aPageDesc, false); + SwPageDesc* pNewPageDesc = m_rDoc.MakePageDesc(m_aOld.GetName(), &aPageDesc, false); + if (m_aOld.GetName() == m_aOld.GetFollowName()) + pNewPageDesc->SetFollow(pNewPageDesc); } void SwUndoPageDescDelete::DoImpl()
