]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetRef.cpp
doubly stupid bug fix.
[lyx.git] / src / insets / InsetRef.cpp
index ddbff5ebb5a362e5b7aece417a6ca17f286321f2..84a602e8648a0e63da8f0bd713a2445851fd94ee 100644 (file)
@@ -160,15 +160,28 @@ void InsetRef::addToToc(Buffer const & buf,
 {
        docstring const & label = getParam("reference");
        Toc & toc = buf.tocBackend().toc("label");
-       Toc::const_iterator it = toc.begin();
-       Toc::const_iterator end = toc.end();
+       Toc::iterator it = toc.begin();
+       Toc::iterator end = toc.end();
        for (; it != end; ++it) {
-               if (it->str() == label) {
-                       ++it;
-                       toc.insert(it, TocItem(cpit, 1, getScreenLabel(buf)));
+               if (it->str() == label)
                        break;
-               }
        }
+
+       docstring const reflabel = getScreenLabel(buf);
+       if (it == end) {
+               // This label has not been parsed yet so we just add it temporarily.
+               // InsetLabel::addTocToc() will fix that later.
+               toc.push_back(TocItem(cpit, 0, label));
+               toc.push_back(TocItem(cpit, 1, reflabel));
+               return;
+       }
+
+       // The Toc item for this label already exists so let's add
+       // this inset to this node.
+       ++it;
+       while (it != end && it->str() == reflabel)
+               ++it;
+       toc.insert(it, TocItem(cpit, 1, reflabel));
 }