From 2f236b01e0eb9dd7388cc446e9d0c58a3b31208f Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 21 Oct 2021 19:14:06 +0200 Subject: [PATCH] Make sure that language is "latex" in InsetArgument when pass-thru. The code that determine whether an InsetArgument is passThru is complex and lives in updateBuffer. This patch factors out the code in a new init method and calls it also in doInsetInsert when inserting a InsetArgument. Fixes bug #12143. --- src/Text3.cpp | 8 ++++++- src/insets/InsetArgument.cpp | 41 ++++++++++++++++++++---------------- src/insets/InsetArgument.h | 3 +++ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/Text3.cpp b/src/Text3.cpp index b1bf879a55..c8483fe380 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -252,7 +252,7 @@ static bool doInsertInset(Cursor & cur, Text * text, cur.recordUndo(); if (cmd.action() == LFUN_ARGUMENT_INSERT) { bool cotextinsert = false; - InsetArgument const * const ia = static_cast(inset); + InsetArgument * const ia = static_cast(inset); Layout const & lay = cur.paragraph().layout(); Layout::LaTeXArgMap args = lay.args(); Layout::LaTeXArgMap::const_iterator const lait = args.find(ia->name()); @@ -275,6 +275,7 @@ static bool doInsertInset(Cursor & cur, Text * text, else ds = cur.paragraph().asString(); text->insertInset(cur, inset); + ia->init(cur.paragraph()); if (edit) inset->edit(cur, true); // Now put co-text into inset @@ -321,6 +322,11 @@ static bool doInsertInset(Cursor & cur, Text * text, inset_text->setOuterFont(cur.bv(), font.fontInfo()); } + if (cmd.action() == LFUN_ARGUMENT_INSERT) { + InsetArgument * const ia = static_cast(inset); + ia->init(cur.paragraph()); + } + if (edit) inset->edit(cur, true); diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index 811b8845d3..88085cfb03 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -63,31 +63,30 @@ void InsetArgument::read(Lexer & lex) } -void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted) +void InsetArgument::init(Paragraph const & par) { - bool const insetlayout = !it.paragraph().layout().hasArgs(); + Inset const & ininset = par.inInset(); + bool const insetlayout = !par.layout().hasArgs(); Layout::LaTeXArgMap const args = insetlayout ? - it.inset().getLayout().args() : it.paragraph().layout().args(); + ininset.getLayout().args() : par.layout().args(); pass_thru_context_ = insetlayout ? - it.inset().getLayout().isPassThru() : it.paragraph().layout().pass_thru; + ininset.getLayout().isPassThru() : par.layout().pass_thru; // Record PassThru status in order to act on changes. bool const former_pass_thru = pass_thru_; // Handle pre 2.1 ArgInsets (lyx2lyx cannot classify them) // "999" is the conventional name given to those by lyx2lyx if (name_ == "999") { - int const req = insetlayout ? it.inset().getLayout().requiredArgs() - : it.paragraph().layout().requiredArgs(); - int const opts = insetlayout ? it.inset().getLayout().optArgs() - : it.paragraph().layout().optArgs(); + int const req = insetlayout ? ininset.getLayout().requiredArgs() + : par.layout().requiredArgs(); + int const opts = insetlayout ? ininset.getLayout().optArgs() + : par.layout().optArgs(); int nr = 0; int ours = 0; - InsetList::const_iterator parit = it.paragraph().insetList().begin(); - InsetList::const_iterator parend = it.paragraph().insetList().end(); - for (; parit != parend; ++parit) { - if (parit->inset->lyxCode() == ARG_CODE) { + for (InsetList::Element const & elt : par.insetList()) { + if (elt.inset->lyxCode() == ARG_CODE) { ++nr; - if (parit->inset == this) + if (elt.inset == this) ours = nr; } } @@ -133,8 +132,8 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype, bool is_toc_caption_ = true; // empty if AddToToc is not set caption_of_toc_ = insetlayout - ? it.inset().getLayout().tocType() - : it.paragraph().layout().tocType(); + ? ininset.getLayout().tocType() + : par.layout().tocType(); } switch ((*lait).second.passthru) { @@ -157,13 +156,19 @@ void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype, bool if (former_pass_thru != pass_thru_) { // PassThru status changed. We might need to update // the language of the contents - Language const * l = insetlayout - ? it.inset().buffer().language() - : it.buffer()->language(); + // Language const * l = insetlayout + // ? it.inset().buffer().language() + // : it.buffer()->language(); + Language const * l = ininset.buffer().language(); fixParagraphLanguage(l); } setButtonLabel(); +} + +void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted) +{ + init(it.paragraph()); InsetCollapsible::updateBuffer(it, utype, deleted); } diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index 7488e4586c..34f4309cb0 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -51,6 +51,9 @@ public: InsetCode lyxCode() const override { return ARG_CODE; } /// docstring layoutName() const override { return from_ascii("Argument"); } + + /// Initialize the members of this inset when inserted in \c par. + void init(Paragraph const & par); /// Update the label string of this inset void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override; /// -- 2.39.2