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.
This commit is contained in:
Jean-Marc Lasgouttes 2021-10-21 19:14:06 +02:00
parent 3444a5a54a
commit 2f236b01e0
3 changed files with 33 additions and 19 deletions

View File

@ -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<InsetArgument const *>(inset);
InsetArgument * const ia = static_cast<InsetArgument *>(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<InsetArgument *>(inset);
ia->init(cur.paragraph());
}
if (edit)
inset->edit(cur, true);

View File

@ -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);
}

View File

@ -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;
///