[LyX/master] Make sure that language is "latex" in InsetArgument when pass-thru.
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Thu Oct 21 20:19:53 UTC 2021
commit 2f236b01e0eb9dd7388cc446e9d0c58a3b31208f
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Thu Oct 21 19:14:06 2021 +0200
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 b1bf879..c8483fe 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<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);
diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp
index 811b884..88085cf 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 7488e45..34f4309 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;
///
More information about the lyx-cvs
mailing list