mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Introduce environment-split previous
This one checks for an environment in the previous paragraph (outside the nesting scope).
This commit is contained in:
parent
dfaa4e9466
commit
2907160fff
@ -113,7 +113,7 @@ Format 4
|
||||
\bind "M-a Down" "outline-down"
|
||||
|
||||
|
||||
\bind "M-a Return" "environment-split"
|
||||
\bind "M-a Return" "command-alternatives environment-split ; environment-split previous"
|
||||
\bind "M-a S-Return" "environment-split outer"
|
||||
|
||||
# Obsolete Tastenbelegung: in die persönliche *.bind Datei kopieren und
|
||||
|
@ -126,7 +126,7 @@ Format 4
|
||||
\bind "M-p Up" "outline-up"
|
||||
\bind "M-p Down" "outline-down"
|
||||
|
||||
\bind "M-p Return" "environment-split"
|
||||
\bind "M-p Return" "command-alternatives environment-split ; environment-split previous"
|
||||
\bind "M-p S-Return" "environment-split outer"
|
||||
|
||||
|
||||
|
@ -1513,9 +1513,11 @@ void LyXAction::init()
|
||||
/*!
|
||||
* \var lyx::FuncCode lyx::LFUN_ENVIRONMENT_SPLIT
|
||||
* \li Action: Splits the current environment with a Separator.
|
||||
* \li Syntax: environment-split [outer]
|
||||
* \li Syntax: environment-split [outer|previous]
|
||||
* \li Params: outer: If this is given, LyX will split the outermost environment in
|
||||
* the current nesting hierarchy.
|
||||
* previous: If this is given, LyX will split the environment in the previous
|
||||
* paragraph (is there is one).
|
||||
* \li Origin: spitz, 23 Dec 2012
|
||||
* \endvar
|
||||
*/
|
||||
|
@ -1492,23 +1492,33 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
||||
|
||||
case LFUN_ENVIRONMENT_SPLIT: {
|
||||
bool const outer = cmd.argument() == "outer";
|
||||
bool const previous = cmd.argument() == "previous";
|
||||
Paragraph const & para = cur.paragraph();
|
||||
docstring layout = para.layout().name();
|
||||
docstring layout;
|
||||
if (para.layout().isEnvironment())
|
||||
layout = para.layout().name();
|
||||
depth_type split_depth = cur.paragraph().params().depth();
|
||||
if (outer) {
|
||||
// check if we have an environment in our nesting hierarchy
|
||||
if (outer || previous) {
|
||||
// check if we have an environment in our scope
|
||||
pit_type pit = cur.pit();
|
||||
Paragraph cpar = pars_[pit];
|
||||
while (true) {
|
||||
if (pit == 0 || cpar.params().depth() == 0)
|
||||
if (pit == 0)
|
||||
break;
|
||||
--pit;
|
||||
cpar = pars_[pit];
|
||||
if (layout.empty() && previous
|
||||
&& cpar.layout().isEnvironment()
|
||||
&& cpar.params().depth() <= split_depth)
|
||||
layout = cpar.layout().name();
|
||||
if (cpar.params().depth() < split_depth
|
||||
&& cpar.layout().isEnvironment()) {
|
||||
layout = cpar.layout().name();
|
||||
if (!previous)
|
||||
layout = cpar.layout().name();
|
||||
split_depth = cpar.params().depth();
|
||||
}
|
||||
if (cpar.params().depth() == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cur.pos() > 0)
|
||||
@ -3180,6 +3190,19 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
|
||||
enable = res;
|
||||
break;
|
||||
}
|
||||
else if (cmd.argument() == "previous") {
|
||||
// look if we have an environment in the previous par
|
||||
pit_type pit = cur.pit();
|
||||
Paragraph cpar = pars_[pit];
|
||||
if (pit > 0) {
|
||||
--pit;
|
||||
cpar = pars_[pit];
|
||||
enable = cpar.layout().isEnvironment();
|
||||
break;
|
||||
}
|
||||
enable = false;
|
||||
break;
|
||||
}
|
||||
else if (cur.paragraph().layout().isEnvironment()) {
|
||||
enable = true;
|
||||
break;
|
||||
|
@ -1859,19 +1859,25 @@ void MenuDefinition::expandEnvironmentSeparators(BufferView const * bv)
|
||||
Paragraph const & par = text->getPar(pit);
|
||||
docstring const curlayout = par.layout().name();
|
||||
docstring outerlayout;
|
||||
docstring prevlayout;
|
||||
depth_type current_depth = par.params().depth();
|
||||
// check if we have an environment in our nesting hierarchy
|
||||
// check if we have an environment in our scope
|
||||
Paragraph cpar = par;
|
||||
while (true) {
|
||||
if (pit == 0 || cpar.params().depth() == 0)
|
||||
if (pit == 0)
|
||||
break;
|
||||
--pit;
|
||||
cpar = text->getPar(pit);
|
||||
if (cpar.layout().isEnvironment() && prevlayout.empty()
|
||||
&& cpar.params().depth() <= current_depth)
|
||||
prevlayout = cpar.layout().name();
|
||||
if (cpar.params().depth() < current_depth
|
||||
&& cpar.layout().isEnvironment()) {
|
||||
outerlayout = cpar.layout().name();
|
||||
current_depth = cpar.params().depth();
|
||||
}
|
||||
if (cpar.params().depth() == 0)
|
||||
break;
|
||||
}
|
||||
if (par.layout().isEnvironment()) {
|
||||
docstring const label =
|
||||
@ -1880,6 +1886,14 @@ void MenuDefinition::expandEnvironmentSeparators(BufferView const * bv)
|
||||
add(MenuItem(MenuItem::Command, toqstr(label),
|
||||
FuncRequest(LFUN_ENVIRONMENT_SPLIT)));
|
||||
}
|
||||
else if (!prevlayout.empty()) {
|
||||
docstring const label =
|
||||
bformat(_("Start New Environment (%1$s)"),
|
||||
translateIfPossible(prevlayout));
|
||||
add(MenuItem(MenuItem::Command, toqstr(label),
|
||||
FuncRequest(LFUN_ENVIRONMENT_SPLIT,
|
||||
from_ascii("previous"))));
|
||||
}
|
||||
if (!outerlayout.empty()) {
|
||||
docstring const label =
|
||||
bformat(_("Start New Parent Environment (%1$s)"),
|
||||
|
Loading…
Reference in New Issue
Block a user