From 61cf196631a2a846e0d3b8b83c0805cf4d1d14b2 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 25 Oct 2019 17:40:02 +0200 Subject: sw ContinuousEndnotes: fix moving them to the previous page If you delete the first page of a document, the endnotes remained on an empty last page. Fix this. Change-Id: I70187c4c32490178366e024606926d3cebcaa680 Reviewed-on: https://gerrit.libreoffice.org/81512 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/extras/layout/layout.cxx | 26 ++++++++++++++++++++++++++ sw/source/core/text/txtftn.cxx | 6 +++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index c12c55082ee3..d8cef7ef98aa 100644 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -3361,6 +3361,32 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testContinuousEndnotesInsertPageAtStart) assertXPath(pXmlDoc, "/root/page[3]/ftncont", 1); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testContinuousEndnotesDeletePageAtStart) +{ + // Create a new document with CONTINUOUS_ENDNOTES enabled. + SwDoc* pDoc = createDoc(); + pDoc->getIDocumentSettingAccess().set(DocumentSettingId::CONTINUOUS_ENDNOTES, true); + + // Insert a second page, and an endnote on the 2nd page (both the anchor and the endnote is on + // the 2nd page). + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertPageBreak(); + pWrtShell->InsertFootnote("endnote", /*bEndNote=*/true, /*bEdit=*/false); + + // Remove the empty page at the start of the document. + pWrtShell->SttEndDoc(/*bStart=*/true); + pWrtShell->DelRight(); + + // Make sure that the endnote is moved from the 2nd page to the 1st one. + xmlDocPtr pXmlDoc = parseLayoutDump(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 2 + // i.e. the endnote remained on an (otherwise) empty 2nd page. + assertXPath(pXmlDoc, "/root/page", 1); + assertXPath(pXmlDoc, "/root/page[1]/ftncont", 1); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx index e9e7046e66fd..27dfe303d58f 100644 --- a/sw/source/core/text/txtftn.cxx +++ b/sw/source/core/text/txtftn.cxx @@ -52,6 +52,7 @@ #include #include #include +#include using namespace ::com::sun::star; @@ -578,7 +579,10 @@ void SwTextFrame::ConnectFootnote( SwTextFootnote *pFootnote, const SwTwips nDea mbFootnote = true; mbInFootnoteConnect = true; // Just reset! - const bool bEnd = pFootnote->GetFootnote().IsEndNote(); + // See if pFootnote is an endnote on a separate endnote page. + const IDocumentSettingAccess& rSettings = GetDoc().getIDocumentSettingAccess(); + bool bContinuousEndnotes = rSettings.get(DocumentSettingId::CONTINUOUS_ENDNOTES); + const bool bEnd = pFootnote->GetFootnote().IsEndNote() && !bContinuousEndnotes; // We want to store this value, because it is needed as a fallback // in GetFootnoteLine(), if there is no paragraph information available -- cgit