Introduce environment-split before

This one prepends the new environment rather than appending it.

Easy way to add a new beamer frame before the current one.
This commit is contained in:
Juergen Spitzmueller 2017-12-28 14:17:40 +01:00
parent 2907160fff
commit 87a6c75d9d
3 changed files with 29 additions and 12 deletions

View File

@ -1515,9 +1515,11 @@ void LyXAction::init()
* \li Action: Splits the current environment with a Separator. * \li Action: Splits the current environment with a Separator.
* \li Syntax: environment-split [outer|previous] * \li Syntax: environment-split [outer|previous]
* \li Params: outer: If this is given, LyX will split the outermost environment in * \li Params: outer: If this is given, LyX will split the outermost environment in
* the current nesting hierarchy. the current nesting hierarchy.
* previous: If this is given, LyX will split the environment in the previous previous: If this is given, LyX will split the environment in the previous
* paragraph (is there is one). paragraph (is there is one).
before: If this is given, the new environment will be appended rather than
prepended.
* \li Origin: spitz, 23 Dec 2012 * \li Origin: spitz, 23 Dec 2012
* \endvar * \endvar
*/ */
@ -3059,10 +3061,11 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_PARAGRAPH_BREAK * \var lyx::FuncCode lyx::LFUN_PARAGRAPH_BREAK
* \li Action: Breaks the current paragraph at the current location. * \li Action: Breaks the current paragraph at the current location.
* \li Notion: Removes the selection. * \li Notion: Removes the selection.
* \li Syntax: paragraph-break [<LAYOUT>] * \li Syntax: paragraph-break [<LAYOUT>] [ignoresep]
* \li Params: <LAYOUT>: "inverse" - decreases depth by one (or change layout * \li Params: <LAYOUT>: "inverse" - decreases depth by one (or change layout
to default layout) when the cursor is at the end of to default layout) when the cursor is at the end of
the line. the line.
ignoresep: Do not account for paragraph separators while breaking.
* \endvar * \endvar
*/ */
{ LFUN_PARAGRAPH_BREAK, "paragraph-break", Noop, Edit }, { LFUN_PARAGRAPH_BREAK, "paragraph-break", Noop, Edit },

View File

@ -1141,9 +1141,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
Font const f(inherit_font, cur.current_font.language()); Font const f(inherit_font, cur.current_font.language());
pars_[cur.pit() - 1].resetFonts(f); pars_[cur.pit() - 1].resetFonts(f);
} else { } else {
if (par.isEnvSeparator(cur.pos())) if (par.isEnvSeparator(cur.pos()) && cmd.getArg(1) != "ignoresep")
cur.posForward(); cur.posForward();
breakParagraph(cur, cmd.argument() == "inverse"); breakParagraph(cur, cmd.getArg(0) == "inverse");
} }
cur.resetAnchor(); cur.resetAnchor();
// If we have a list and autoinsert item insets, // If we have a list and autoinsert item insets,
@ -1493,6 +1493,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_ENVIRONMENT_SPLIT: { case LFUN_ENVIRONMENT_SPLIT: {
bool const outer = cmd.argument() == "outer"; bool const outer = cmd.argument() == "outer";
bool const previous = cmd.argument() == "previous"; bool const previous = cmd.argument() == "previous";
bool const before = cmd.argument() == "before";
Paragraph const & para = cur.paragraph(); Paragraph const & para = cur.paragraph();
docstring layout; docstring layout;
if (para.layout().isEnvironment()) if (para.layout().isEnvironment())
@ -1521,7 +1522,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
break; break;
} }
} }
if (cur.pos() > 0) if (before)
cur.top().setPitPos(cur.pit(), 0);
if (before || cur.pos() > 0)
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK)); lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
if (outer) { if (outer) {
while (cur.paragraph().params().depth() > split_depth) while (cur.paragraph().params().depth() > split_depth)
@ -1530,7 +1533,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
DocumentClass const & tc = bv->buffer().params().documentClass(); DocumentClass const & tc = bv->buffer().params().documentClass();
lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name())); lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name()));
lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain")); lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse")); if (before) {
cur.backwardPos();
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse ignoresep"));
while (cur.paragraph().params().depth() < split_depth)
lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
}
else
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout)); lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
break; break;

View File

@ -1880,15 +1880,19 @@ void MenuDefinition::expandEnvironmentSeparators(BufferView const * bv)
break; break;
} }
if (par.layout().isEnvironment()) { if (par.layout().isEnvironment()) {
docstring const label = docstring label = bformat(_("Prepend New Environment (%1$s)"),
bformat(_("Start New Environment (%1$s)"), translateIfPossible(curlayout));
add(MenuItem(MenuItem::Command, toqstr(label),
FuncRequest(LFUN_ENVIRONMENT_SPLIT,
from_ascii("before"))));
label = bformat(_("Append New Environment (%1$s)"),
translateIfPossible(curlayout)); translateIfPossible(curlayout));
add(MenuItem(MenuItem::Command, toqstr(label), add(MenuItem(MenuItem::Command, toqstr(label),
FuncRequest(LFUN_ENVIRONMENT_SPLIT))); FuncRequest(LFUN_ENVIRONMENT_SPLIT)));
} }
else if (!prevlayout.empty()) { else if (!prevlayout.empty()) {
docstring const label = docstring const label =
bformat(_("Start New Environment (%1$s)"), bformat(_("Append New Environment (%1$s)"),
translateIfPossible(prevlayout)); translateIfPossible(prevlayout));
add(MenuItem(MenuItem::Command, toqstr(label), add(MenuItem(MenuItem::Command, toqstr(label),
FuncRequest(LFUN_ENVIRONMENT_SPLIT, FuncRequest(LFUN_ENVIRONMENT_SPLIT,
@ -1896,7 +1900,7 @@ void MenuDefinition::expandEnvironmentSeparators(BufferView const * bv)
} }
if (!outerlayout.empty()) { if (!outerlayout.empty()) {
docstring const label = docstring const label =
bformat(_("Start New Parent Environment (%1$s)"), bformat(_("Append New Parent Environment (%1$s)"),
translateIfPossible(outerlayout)); translateIfPossible(outerlayout));
add(MenuItem(MenuItem::Command, toqstr(label), add(MenuItem(MenuItem::Command, toqstr(label),
FuncRequest(LFUN_ENVIRONMENT_SPLIT, FuncRequest(LFUN_ENVIRONMENT_SPLIT,