X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FTocBackend.C;h=48847483a05e807b8ac893e735cd8798827b3128;hb=e7f4618bcce770369cf46335c2c7f0164b4b8857;hp=327face5d85d23cc8f177d32afbdc72836ac85ae;hpb=2734cc154853c61a7ea54bfeea3adc908f68bdc5;p=lyx.git diff --git a/src/TocBackend.C b/src/TocBackend.C index 327face5d8..48847483a0 100644 --- a/src/TocBackend.C +++ b/src/TocBackend.C @@ -143,6 +143,7 @@ void TocBackend::update() BufferParams const & bufparams = buffer_->params(); const int min_toclevel = bufparams.getLyXTextClass().min_toclevel(); + Toc & toc = tocs_["tableofcontents"]; ParConstIterator pit = buffer_->par_iterator_begin(); ParConstIterator end = buffer_->par_iterator_end(); for (; pit != end; ++pit) { @@ -155,12 +156,14 @@ void TocBackend::update() InsetList::const_iterator it = pit->insetlist.begin(); InsetList::const_iterator end = pit->insetlist.end(); for (; it != end; ++it) { - it->inset->addToToc(tocs_, *buffer_); - switch (it->inset->lyxCode()) { + InsetBase & inset = *it->inset; + inset.addToToc(tocs_, *buffer_); + switch (inset.lyxCode()) { case InsetBase::OPTARG_CODE: { if (!tocstring.empty()) break; - Paragraph const & par = *static_cast(it->inset)->paragraphs().begin(); + Paragraph const & par = + *static_cast(inset).paragraphs().begin(); if (!pit->getLabelstring().empty()) tocstring = pit->getLabelstring() + ' '; tocstring += par.asString(*buffer_, false); @@ -179,8 +182,8 @@ void TocBackend::update() // insert this into the table of contents if (tocstring.empty()) tocstring = pit->asString(*buffer_, true); - TocItem const item(pit, toclevel - min_toclevel, tocstring); - tocs_["tableofcontents"].push_back(item); + toc.push_back( + TocItem(pit, toclevel - min_toclevel, tocstring)); } } @@ -200,8 +203,19 @@ TocIterator const TocBackend::item( Toc const & toc_vector = toclist_it->second; TocIterator last = toc_vector.begin(); TocIterator it = toc_vector.end(); + if (it == last) + return it; + --it; + ParConstIterator par_it_text = par_it; + if (par_it_text.inMathed()) + // It would be better to do + // par_it_text.backwardInset(); + // but this method does not exist. + while (par_it_text.inMathed()) + par_it_text.backwardPos(); + for (; it != last; --it) { // A good solution for Items inside insets would be to do: @@ -212,7 +226,7 @@ TocIterator const TocBackend::item( // But for an unknown reason, std::distance(current, it->par_it_) always // returns a positive value and std::distance(it->par_it_, current) takes forever... // So for now, we do: - if (it->par_it_.pit() <= par_it.pit()) + if (it->par_it_.pit() <= par_it_text.pit()) return it; } @@ -221,7 +235,7 @@ TocIterator const TocBackend::item( } -void TocBackend::asciiTocList(string const & type, odocstream & os) const +void TocBackend::writePlaintextTocList(string const & type, odocstream & os) const { TocList::const_iterator cit = tocs_.find(type); if (cit != tocs_.end()) {