From: Juergen Spitzmueller Date: Thu, 28 Mar 2024 17:03:54 +0000 (+0100) Subject: Do not enter page break in heading (#13040) X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=698f922d19eb28f3ca84cc9f6a1bb5aaf3ba0301;p=features.git Do not enter page break in heading (#13040) Rather than that, put it before or after, or disallow, depending on the position. --- 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: