diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 6acbdb47c2..58736abb8f 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -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 + * \li Syntax: argument-insert [force] * \li Params: : see layout declarations + * force: Insert argument even if already there. * \li Origin: vermeer, 12 Aug 2002 * \endvar */ diff --git a/src/Text3.cpp b/src/Text3.cpp index 8d37e790b3..2f94de5f2e 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index b19b3841ae..a733588ef2 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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;