sw/inc/editsh.hxx                                |    8 +--
 sw/qa/uitest/data/tdf114343_titlePageDialog.odt  |binary
 sw/qa/uitest/data/tdf114343_titlePageDialogB.odt |binary
 sw/qa/uitest/writer_tests5/titlePageWizard3.py   |   52 +++++++++++++++++++++++
 sw/source/ui/misc/titlepage.cxx                  |    3 +
 5 files changed, 59 insertions(+), 4 deletions(-)

New commits:
commit 932c8227717f44877d77659c444845d39f4156ce
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Thu Sep 18 11:34:59 2025 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Fri Sep 19 22:41:54 2025 +0200

    tdf#114343 titlepage: DoSpecialInsert (Alt-Enter) when necessary
    
    If the document starts with a TOC or a table,
    then the title page wizard (Format - Title page)
    fails to (properly) insert a page before.
    
    (note that while it DID insert a page before the TOC,
    that para-with-page-break is all still "part of the TOC"
    and so when the TOC is refreshed, the page break is lost.)
    
    make -srj1 UITest_writer_tests5 \
        UITEST_TEST_NAME=titlePageWizard3.tdf114343.test_tdf114343 \
        SAL_USE_VCLPLUGIN=gen
    
    make -srj1 UITest_writer_tests5 \
        UITEST_TEST_NAME=titlePageWizard3.tdf114343.test2_tdf114343 \
        SAL_USE_VCLPLUGIN=gen
    
    Change-Id: I0eb865259889601c0918096d8dd51fc50d0dca52
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191164
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index f66ede9d56e2..990bb7adc07a 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -911,10 +911,10 @@ public:
 
     /** Special insert: Insert a new text node just before or after a section 
or
      table, if the cursor is positioned at the start/end of said
-     section/table. The purpose of the method is to allow users to inert text
-     at certain 'impossible' position, e.g. before a table at the document
-     start or between to sections. */
-    void DoSpecialInsert();
+     section/table. The purpose of the method is to allow users to insert text
+     at certain 'impossible' positions, e.g. before a table at the document
+     start or between two sections. */
+    SW_DLLPUBLIC void DoSpecialInsert();
     bool CanSpecialInsert() const;
 
     /// Optimizing UI.
diff --git a/sw/qa/uitest/data/tdf114343_titlePageDialog.odt 
b/sw/qa/uitest/data/tdf114343_titlePageDialog.odt
new file mode 100644
index 000000000000..ca943ce51799
Binary files /dev/null and b/sw/qa/uitest/data/tdf114343_titlePageDialog.odt 
differ
diff --git a/sw/qa/uitest/data/tdf114343_titlePageDialogB.odt 
b/sw/qa/uitest/data/tdf114343_titlePageDialogB.odt
new file mode 100644
index 000000000000..3b1d1bbb21fb
Binary files /dev/null and b/sw/qa/uitest/data/tdf114343_titlePageDialogB.odt 
differ
diff --git a/sw/qa/uitest/writer_tests5/titlePageWizard3.py 
b/sw/qa/uitest/writer_tests5/titlePageWizard3.py
new file mode 100644
index 000000000000..599733d0ae2f
--- /dev/null
+++ b/sw/qa/uitest/writer_tests5/titlePageWizard3.py
@@ -0,0 +1,52 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_url_for_data_file
+#import time
+
+# This tests the Format->Title Page wizard, specifically inserting pages 
before a TOC or table,
+# which are edge cases. (The TOC is harder to test because it works but gets 
lost on a TOC update.)
+class tdf114343(UITestCase):
+    def test_tdf114343(self):  # table test
+        with 
self.ui_test.load_file(get_url_for_data_file("tdf114343_titlePageDialog.odt")) 
as document:
+
+            # Confirm the starting state.
+            self.assertEqual(document.CurrentController.PageCount, 1)
+            #time.sleep(2)
+
+            #dialog Title Page
+            with 
self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog") as xDialog:
+                #Insert three title/index pages at the end of the document 
(plus a content page).
+                newPages = xDialog.getChild("RB_INSERT_NEW_PAGES")
+                newPages.executeAction("CLICK", tuple())
+                #time.sleep(4)
+
+            # an extra paragraph was added before TOC/Table so splitNode could 
work.
+            self.assertEqual(document.CurrentController.PageCount, 2)
+            #time.sleep(5)
+
+    def test2_tdf114343(self):  # TOC test
+        with 
self.ui_test.load_file(get_url_for_data_file("tdf114343_titlePageDialogB.odt")) 
as document:
+
+            # Confirm the starting state.
+            self.assertEqual(document.CurrentController.PageCount, 1)
+
+            #dialog Title Page
+            with 
self.ui_test.execute_dialog_through_command(".uno:TitlePageDialog") as xDialog:
+                #Insert three title/index pages at the end of the document 
(plus a content page).
+                newPages = xDialog.getChild("RB_INSERT_NEW_PAGES")
+                newPages.executeAction("CLICK", tuple())
+                #time.sleep(4)
+
+            # update the TOC
+            self.xUITest.executeCommand(".uno:UpdateAllIndexes")
+            # an extra paragraph was added before TOC/Table so splitNode could 
work.
+            self.assertEqual(document.CurrentController.PageCount, 2)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/misc/titlepage.cxx b/sw/source/ui/misc/titlepage.cxx
index da92192004dc..d85fb312ac9e 100644
--- a/sw/source/ui/misc/titlepage.cxx
+++ b/sw/source/ui/misc/titlepage.cxx
@@ -300,6 +300,9 @@ IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl, weld::Button&, void)
             // Add one more page as a content page to follow the new title 
pages.
             rWrtShell.InsertPageBreak();
         }
+
+        rWrtShell.DoSpecialInsert(); // Alt-Enter: if needed, inserts empty 
para before table/TOC
+
         for (sal_uInt16 nI = 0; nI < nNumTitlePages; ++nI)
             rWrtShell.InsertPageBreak();
         // In order to be able to access these new pages, the layout needs to 
be recalculated first.

Reply via email to