Fix environment-split when at pos 0 of a frame title.

This introduces a force argument to argument-insert that inserts
arguments even if they are already there. We need this here in order
to prevent DEPM.
This commit is contained in:
Juergen Spitzmueller 2017-12-30 12:50:48 +01:00
parent 27901b3a06
commit 1ff34a973d
3 changed files with 21 additions and 4 deletions

View File

@ -302,8 +302,9 @@ void LyXAction::init()
/*!
* \var lyx::FuncCode lyx::LFUN_ARGUMENT_INSERT
* \li Action: Inserts an argument (short title) inset.
* \li Syntax: argument-insert <argument nr>
* \li Syntax: argument-insert <argument nr> [force]
* \li Params: <argument nr>: see layout declarations
* force: Insert argument even if already there.
* \li Origin: vermeer, 12 Aug 2002
* \endvar
*/

View File

@ -1505,6 +1505,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
bool const outer = cmd.argument() == "outer";
bool const previous = cmd.argument() == "previous";
bool const before = cmd.argument() == "before";
bool const normal = cmd.argument().empty();
Paragraph const & para = cur.paragraph();
docstring layout;
if (para.layout().isEnvironment())
@ -1535,6 +1536,20 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
if (before)
cur.top().setPitPos(cur.pit(), 0);
DocumentClass const & tc = bv->buffer().params().documentClass();
if (normal && cur.pos() == 0 && isFirstInSequence(cur.pit())) {
Layout::LaTeXArgMap args = tc[layout].args();
Layout::LaTeXArgMap::const_iterator lait = args.begin();
Layout::LaTeXArgMap::const_iterator const laend = args.end();
for (; lait != laend; ++lait) {
Layout::latexarg arg = (*lait).second;
if (arg.autoinsert) {
FuncRequest cmd(LFUN_ARGUMENT_INSERT, (*lait).first + " force");
lyx::dispatch(cmd);
}
}
cur.forwardPos();
}
if (before || cur.pos() > 0)
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK));
else if (previous && cur.nextInset() && cur.nextInset()->lyxCode() == SEPARATOR_CODE)
@ -1543,7 +1558,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
while (cur.paragraph().params().depth() > split_depth)
lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
}
DocumentClass const & tc = bv->buffer().params().documentClass();
lyx::dispatch(FuncRequest(LFUN_LAYOUT, from_ascii("\"") + tc.plainLayout().name()
+ from_ascii("\" ignoreautonests")));
lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
@ -2860,6 +2874,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
code = ARG_CODE;
allow_in_passthru = true;
string const arg = cmd.getArg(0);
bool const force = cmd.getArg(1) == "force";
if (arg.empty()) {
enable = false;
break;
@ -2893,7 +2908,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
break;
for (auto const & table : pars_[pit].insetList())
if (InsetArgument const * ins = table.inset->asInsetArgument())
if (ins->name() == arg) {
if (ins->name() == arg && !force) {
// we have this already
enable = false;
break;

View File

@ -360,6 +360,7 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_ARGUMENT_INSERT: {
string const arg = cmd.getArg(0);
bool const force = cmd.getArg(1) == "force";
if (arg.empty()) {
status.setEnabled(false);
return true;
@ -374,7 +375,7 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
for (Paragraph const & par : paragraphs())
for (auto const & table : par.insetList())
if (InsetArgument const * ins = table.inset->asInsetArgument())
if (ins->name() == arg) {
if (ins->name() == arg && !force) {
// we have this already
status.setEnabled(false);
return true;