commit c55490b52e246074232581532193b14a58f88a9b
Author: Juergen Spitzmueller <[email protected]>
Date: Thu Jul 17 08:55:37 2025 +0200
Terminate local counters in UI
they leaked into global ones (e.g. footnote in a section heading)
---
src/Buffer.cpp | 3 +--
src/insets/InsetCaption.cpp | 10 ++++------
src/insets/InsetCaptionable.cpp | 11 +++++------
src/insets/InsetFlex.cpp | 19 +++++++++----------
src/insets/InsetFoot.cpp | 9 +++------
5 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index f282e2331a..69629730cd 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -2467,9 +2467,8 @@ void Buffer::getLabelList(vector<std::tuple<docstring,
docstring, docstring>> &
list.clear();
shared_ptr<Toc> toc = d->toc_backend.toc("label");
for (auto const & tocit : *toc) {
- if (tocit.depth() == 0) {
+ if (tocit.depth() == 0)
list.push_back(make_tuple(tocit.str(),
tocit.asString(), tocit.prettyStr()));
- }
}
}
diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp
index 48c492c9e4..b215cab10d 100644
--- a/src/insets/InsetCaption.cpp
+++ b/src/insets/InsetCaption.cpp
@@ -400,10 +400,9 @@ void InsetCaption::updateBuffer(ParIterator const & it,
UpdateType utype, bool c
string const & lang =
it.paragraph().getParLanguage(master.params())->code();
Counters & cnts = tclass.counters();
string const & type = cnts.current_float();
- if (utype == OutputUpdate) {
- // counters are local to the caption
- cnts.saveLastCounter();
- }
+ // counters are local to the caption
+ cnts.saveLastCounter();
+
is_deleted_ = deleted;
// Memorize type for addToToc().
floattype_ = type;
@@ -454,8 +453,7 @@ void InsetCaption::updateBuffer(ParIterator const & it,
UpdateType utype, bool c
// Do the real work now.
InsetText::updateBuffer(it, utype, deleted);
- if (utype == OutputUpdate)
- cnts.restoreLastCounter();
+ cnts.restoreLastCounter();
}
diff --git a/src/insets/InsetCaptionable.cpp b/src/insets/InsetCaptionable.cpp
index 6c70b9c094..0b924237d2 100644
--- a/src/insets/InsetCaptionable.cpp
+++ b/src/insets/InsetCaptionable.cpp
@@ -175,10 +175,9 @@ void InsetCaptionable::updateBuffer(ParIterator const &
it, UpdateType utype, bo
buffer().masterBuffer()->params().documentClass().counters();
string const saveflt = cnts.current_float();
bool const savesubflt = cnts.isSubfloat();
- if (utype == OutputUpdate) {
- // counters are local to the float
- cnts.saveLastCounter();
- }
+ // counters are local to the float
+ cnts.saveLastCounter();
+
bool const subflt = hasSubCaptions(it);
// floats can only embed subfloats of their own kind
if (subflt && !saveflt.empty() && saveflt != "senseless")
@@ -189,8 +188,8 @@ void InsetCaptionable::updateBuffer(ParIterator const & it,
UpdateType utype, bo
InsetCollapsible::updateBuffer(it, utype, deleted);
// Restore counters
cnts.current_float(saveflt);
- if (utype == OutputUpdate)
- cnts.restoreLastCounter();
+
+ cnts.restoreLastCounter();
cnts.isSubfloat(savesubflt);
}
diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp
index 43891d5ff6..8f7a0274d6 100644
--- a/src/insets/InsetFlex.cpp
+++ b/src/insets/InsetFlex.cpp
@@ -149,6 +149,14 @@ void InsetFlex::updateBuffer(ParIterator const & it,
UpdateType utype, bool cons
docstring custom_label = translateIfPossible(il.labelstring());
Counters & cnts = bp.documentClass().counters();
+ docstring const & count = il.counter();
+ bool const have_counter = cnts.hasCounter(count);
+ if (have_counter) {
+ // we assume the counter is local to this inset
+ // if this turns out to be wrong in some case, we will
+ // need a layout flag
+ cnts.saveLastCounter();
+ }
// Special case for `subequations' module.
if (il.latextype() == InsetLaTeXType::ENVIRONMENT &&
@@ -174,8 +182,6 @@ void InsetFlex::updateBuffer(ParIterator const & it,
UpdateType utype, bool cons
return;
}
- docstring const & count = il.counter();
- bool const have_counter = cnts.hasCounter(count);
if (have_counter) {
if (!deleted) {
cnts.step(count, utype);
@@ -186,15 +192,8 @@ void InsetFlex::updateBuffer(ParIterator const & it,
UpdateType utype, bool cons
}
setLabel(custom_label);
- bool const save_counter = have_counter && utype == OutputUpdate;
- if (save_counter) {
- // we assume the counter is local to this inset
- // if this turns out to be wrong in some case, we will
- // need a layout flag
- cnts.saveLastCounter();
- }
InsetCollapsible::updateBuffer(it, utype, deleted);
- if (save_counter)
+ if (have_counter)
cnts.restoreLastCounter();
}
diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp
index d6b120b5d1..08bd2915b7 100644
--- a/src/insets/InsetFoot.cpp
+++ b/src/insets/InsetFoot.cpp
@@ -50,10 +50,8 @@ void InsetFoot::updateBuffer(ParIterator const & it,
UpdateType utype, bool cons
{
BufferParams const & bp = buffer().masterBuffer()->params();
Counters & cnts = bp.documentClass().counters();
- if (utype == OutputUpdate) {
- // the footnote counter is local to this inset
- cnts.saveLastCounter();
- }
+ // the footnote counter is local to this inset
+ cnts.saveLastCounter();
intitle_ = false;
infloattable_ = false;
@@ -96,8 +94,7 @@ void InsetFoot::updateBuffer(ParIterator const & it,
UpdateType utype, bool cons
setLabel(custom_label_);
InsetCollapsible::updateBuffer(it, utype, deleted);
- if (utype == OutputUpdate)
- cnts.restoreLastCounter();
+ cnts.restoreLastCounter();
}
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs