From e359d8f5caae9d787a413b0a350542fafef93c16 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 25 Feb 2014 08:00:43 +0100 Subject: [PATCH] Fix caption counter in longtables (see #8993). --- src/Counters.h | 6 ++++++ src/insets/InsetCaption.cpp | 4 +++- src/insets/InsetTabular.cpp | 10 ++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Counters.h b/src/Counters.h index a195889e31..ce122c4140 100644 --- a/src/Counters.h +++ b/src/Counters.h @@ -172,6 +172,10 @@ public: bool isSubfloat() const { return subfloat_; } /// Set the state variable indicating whether we are in a subfloat. void isSubfloat(bool s) { subfloat_ = s; } + /// Are we in a longtable? + bool isLongtable() const { return longtable_; } + /// Set the state variable indicating whether we are in a longtable. + void isLongtable(bool s) { longtable_ = s; } /// \name refstepcounter // @{ @@ -225,6 +229,8 @@ private: std::string current_float_; /// Are we in a subfloat? bool subfloat_; + /// Are we in a longtable? + bool longtable_; /// Used to keep track of active counters. std::vector counter_stack_; /// Same, but for last layout. diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index 2303a1d82a..f1f0983810 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -404,7 +404,9 @@ void InsetCaption::updateBuffer(ParIterator const & it, UpdateType utype) docstring const labelstring = isAscii(lstring) ? master.B_(to_ascii(lstring)) : lstring; if (cnts.hasCounter(counter)) { - cnts.step(counter, utype); + // for longtables, we step the counter upstream + if (!cnts.isLongtable()) + cnts.step(counter, utype); sec = cnts.theCounter(counter, lang); } if (labelstring != master.B_("standard")) { diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index b633c492e1..f89c34a285 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3897,8 +3897,12 @@ void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype) // In a longtable, tell captions what the current float is Counters & cnts = buffer().masterBuffer()->params().documentClass().counters(); string const saveflt = cnts.current_float(); - if (tabular.is_long_tabular) + if (tabular.is_long_tabular) { cnts.current_float("table"); + // in longtables, we only step the counter once + cnts.step(from_ascii("table"), utype); + cnts.isLongtable(true); + } ParIterator it2 = it; it2.forwardPos(); @@ -3907,8 +3911,10 @@ void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype) buffer().updateBuffer(it2, utype); //reset afterwards - if (tabular.is_long_tabular) + if (tabular.is_long_tabular) { cnts.current_float(saveflt); + cnts.isLongtable(false); + } } -- 2.39.2