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: