commit 698f922d19eb28f3ca84cc9f6a1bb5aaf3ba0301
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Thu Mar 28 18:03:54 2024 +0100

    Do not enter page break in heading (#13040)
    
    Rather than that, put it before or after, or disallow,
    depending on the position.
---
 src/Text.cpp | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/Text.cpp b/src/Text.cpp
index e1c8830dc3..d5a1069fa1 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -5720,12 +5720,27 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_NOMENCL_PRINT:
-       case LFUN_NEWPAGE_INSERT:
                // do nothing fancy
                doInsertInset(cur, this, cmd, false, false);
                cur.posForward();
                break;
 
+       case LFUN_NEWPAGE_INSERT: {
+               // When we are in a heading, put the page break in a standard
+               // paragraph before the heading (if cur.pos() == 0) or after
+               // (if cur.pos() == cur.lastpos())
+               if (cur.text()->getTocLevel(cur.pit()) != Layout::NOT_IN_TOC) {
+                       lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
+                       DocumentClass const & tc = 
bv->buffer().params().documentClass();
+                       lyx::dispatch(FuncRequest(LFUN_LAYOUT, from_ascii("\"") 
+ tc.plainLayout().name()
+                                                 + from_ascii("\" 
ignoreautonests")));
+               }
+               // do nothing fancy
+               doInsertInset(cur, this, cmd, false, false);
+               cur.posForward();
+               break;
+       }
+
        case LFUN_SEPARATOR_INSERT: {
                doInsertInset(cur, this, cmd, false, false);
                cur.posForward();
@@ -6956,9 +6971,11 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & 
cmd,
        }
 
        case LFUN_NEWPAGE_INSERT:
-               // not allowed in description items
+               // not allowed in description items and in the midst of sections
                code = NEWPAGE_CODE;
-               enable = !inDescriptionItem(cur);
+               enable = !inDescriptionItem(cur)
+                       && (cur.text()->getTocLevel(cur.pit()) == 
Layout::NOT_IN_TOC
+                           || cur.pos() == 0 || cur.pos() == cur.lastpos());
                break;
 
        case LFUN_LANGUAGE:
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to