]> git.lyx.org Git - lyx.git/blobdiff - src/TocBackend.cpp
* Only enter inset which return true on isActive(). This is the behavior in the curso...
[lyx.git] / src / TocBackend.cpp
index 60736bd8feb5dec3e983f2b82ad3837b51bf017c..db72abdff387379ac4f3ef4566010934a3458d7f 100644 (file)
@@ -123,7 +123,7 @@ Toc const & TocBackend::toc(std::string const & type) const
 
 void TocBackend::updateItem(ParConstIterator const & par_it)
 {
-       // TODO should not happen, 
+       // TODO should not happen,
        // a call to TocBackend::update() is missing somewhere
        if (toc("tableofcontents").empty())
                return;
@@ -144,7 +144,7 @@ void TocBackend::updateItem(ParConstIterator const & par_it)
                if (inset.lyxCode() == Inset::OPTARG_CODE) {
                        if (!tocstring.empty())
                                break;
-                       Paragraph const & par = 
+                       Paragraph const & par =
                                *static_cast<InsetOptArg&>(inset).paragraphs().begin();
                        if (!toc_item->par_it_->getLabelstring().empty())
                                tocstring = toc_item->par_it_->getLabelstring() + ' ';
@@ -184,12 +184,12 @@ void TocBackend::update()
                InsetList::const_iterator end = pit->insetlist.end();
                for (; it != end; ++it) {
                        Inset & inset = *it->inset;
-                       inset.addToToc(tocs_, *buffer_);
+                       inset.addToToc(tocs_, *buffer_, pit);
                        switch (inset.lyxCode()) {
                        case Inset::OPTARG_CODE: {
                                if (!tocstring.empty())
                                        break;
-                               Paragraph const & par = 
+                               Paragraph const & par =
                                        *static_cast<InsetOptArg&>(inset).paragraphs().begin();
                                if (!pit->getLabelstring().empty())
                                        tocstring = pit->getLabelstring() + ' ';
@@ -208,15 +208,15 @@ void TocBackend::update()
                        // insert this into the table of contents
                        if (tocstring.empty())
                                tocstring = pit->asString(*buffer_, true);
-                       toc.push_back(
-                               TocItem(pit, toclevel - min_toclevel, tocstring));
+                       toc.push_back(TocItem(pit, toclevel - min_toclevel,
+                               tocstring));
                }
        }
 }
 
 
-TocIterator const TocBackend::item(
-       std::string const & type, ParConstIterator const & par_it) const
+TocIterator const TocBackend::item(std::string const & type,
+               ParConstIterator const & par_it) const
 {
        TocList::const_iterator toclist_it = tocs_.find(type);
        // Is the type supported?
@@ -239,16 +239,12 @@ TocIterator const TocBackend::item(
                        par_it_text.backwardPos();
 
        for (; it != last; --it) {
-               
-               // A good solution for Items inside insets would be to do:
-               //
-               //if (std::distance(it->par_it_, current) <= 0)
-               //      return it;
-               //
-               // 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_text.pit())
+               // We verify that we don't compare contents of two
+               // different document. This happens when you
+               // have parent and child documents.
+               if (&it->par_it_[0].inset() != &par_it_text[0].inset())
+                       continue;
+               if (it->par_it_ <= par_it_text)
                        return it;
        }