From: Guillaume MM Date: Fri, 12 May 2017 22:51:21 +0000 (+0200) Subject: Fix computation of InsetLayout arguments for InsetText X-Git-Tag: 2.3.0beta1~415 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=1fb0a5f436a861175f7c7f719b936f51178f5ad6;p=features.git Fix computation of InsetLayout arguments for InsetText Do not take the optional arguments from the first paragraph, but from the paragraphs whose layout have no arguments, consistently with the code in InsetArgument::updateBuffer (i.e. what was shown on screen). --- diff --git a/src/Layout.cpp b/src/Layout.cpp index b9674772e2..3d1d781360 100644 --- a/src/Layout.cpp +++ b/src/Layout.cpp @@ -1424,6 +1424,13 @@ void Layout::write(ostream & os) const } +bool Layout::hasArgs() const +{ + return !latexargs_.empty() || !postcommandargs_.empty() || + !itemargs_.empty(); +} + + Layout::LaTeXArgMap Layout::args() const { LaTeXArgMap args = latexargs_; diff --git a/src/Layout.h b/src/Layout.h index 184711b3b4..ba4d26fb37 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -117,6 +117,9 @@ public: LaTeXArgMap const & postcommandargs() const { return postcommandargs_; } /// LaTeXArgMap const & itemargs() const { return itemargs_; } + /// Returns true is the layout has arguments. If false, then an + /// InsetArgument in this layout stands for the parent InsetText. + bool hasArgs() const; /// Returns latexargs() + postcommandargs() + itemargs(). /// But note that it returns a *copy*, not a reference, so do not do /// anything like: diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index cff8cec4fe..e22bcdeb4e 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -63,13 +63,11 @@ void InsetArgument::read(Lexer & lex) void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype) { - Layout::LaTeXArgMap args = it.paragraph().layout().args(); - pass_thru_context_ = it.paragraph().layout().pass_thru; - bool const insetlayout = args.empty(); - if (insetlayout) { - args = it.inset().getLayout().args(); - pass_thru_context_ = it.inset().getLayout().isPassThru(); - } + bool const insetlayout = !it.paragraph().layout().hasArgs(); + Layout::LaTeXArgMap const args = insetlayout ? + it.inset().getLayout().args() : it.paragraph().layout().args(); + pass_thru_context_ = insetlayout ? + it.inset().getLayout().isPassThru() : it.paragraph().layout().pass_thru; // Handle pre 2.1 ArgInsets (lyx2lyx cannot classify them) if (name_ == "999") { diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index afa672dbcf..7680ee5fa9 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -653,6 +653,7 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp, return docstring(); } + void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in, bool const post) const { @@ -662,9 +663,11 @@ void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in, if (isPassThru()) runparams.pass_thru = true; if (post) - latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().postcommandargs(), "post:"); + latexArgInsetsForParent(paragraphs(), os, runparams, + getLayout().postcommandargs(), "post:"); else - latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().latexargs()); + latexArgInsetsForParent(paragraphs(), os, runparams, + getLayout().latexargs()); } diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 0f79ca1838..e292442143 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -610,6 +610,24 @@ void latexArgInsets(ParagraphList const & pars, } +void latexArgInsetsForParent(ParagraphList const & pars, otexstream & os, + OutputParams const & runparams, + Layout::LaTeXArgMap const & latexargs, + string const & prefix) +{ + map ilist; + vector required; + + for (Paragraph const & par : pars) { + if (par.layout().hasArgs()) + // The InsetArguments inside this paragraph refer to this paragraph + continue; + addArgInsets(par, prefix, latexargs, ilist, required); + } + getArgInsets(os, runparams, latexargs, ilist, required, prefix); +} + + namespace { // output the proper paragraph start according to latextype. diff --git a/src/output_latex.h b/src/output_latex.h index fdbc38febb..31125f788d 100644 --- a/src/output_latex.h +++ b/src/output_latex.h @@ -42,14 +42,20 @@ void popPolyglossiaLang(); Non-existing required arguments are output empty: {}. */ void latexArgInsets(Paragraph const & par, - otexstream & os, OutputParams const & runparams, - Layout::LaTeXArgMap const & latexargs, - std::string const & prefix = std::string()); -/// Same for multi-par sequences (e.g. merged environments or InsetLayouts) -void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pit, - otexstream & os, OutputParams const & runparams, - Layout::LaTeXArgMap const & latexargs, - std::string const & prefix = std::string()); + otexstream & os, OutputParams const & runparams, + Layout::LaTeXArgMap const & latexargs, + std::string const & prefix = std::string()); +/// Same for merged environments +void latexArgInsets(ParagraphList const & pars, + ParagraphList::const_iterator pit, + otexstream & os, OutputParams const & runparams, + Layout::LaTeXArgMap const & latexargs, + std::string const & prefix = std::string()); +/// Same for InsetLayouts +void latexArgInsetsForParent(ParagraphList const & pars, otexstream & os, + OutputParams const & runparams, + Layout::LaTeXArgMap const & latexargs, + std::string const & prefix = std::string()); /** Export \p paragraphs of buffer \p buf to LaTeX. Don't use a temporary stringstream for \p os if the final output is supposed to go to a file.