]> git.lyx.org Git - lyx.git/blobdiff - src/dociterator.C
Fix #1736
[lyx.git] / src / dociterator.C
index e8f4c0012b49898fa0bd4c88d2c79cca84a9b699..80a886ae9f95e6366e7fafca28d3208d1c9c5a59 100644 (file)
@@ -57,6 +57,10 @@ InsetBase * DocIterator::nextInset()
        BOOST_ASSERT(!empty());
        if (pos() == lastpos())
                return 0;
+       if (pos() > lastpos()) {
+               lyxerr << "Should not happen, but it does. " << endl;
+               return 0;
+       }
        if (inMathed())
                return nextAtom().nucleus();
        return paragraph().isInset(pos()) ? paragraph().getInset(pos()) : 0;
@@ -410,6 +414,17 @@ void DocIterator::backwardPos()
 }
 
 
+bool DocIterator::hasPart(DocIterator const & it) const
+{
+       // it can't be a part if it is larger
+       if (it.size() > size())
+               return false;
+
+       // as inset adresses are the 'last' level
+       return &it.back().inset() == &operator[](it.size() - 1).inset();
+}
+
+
 std::ostream & operator<<(std::ostream & os, DocIterator const & dit)
 {
        for (size_t i = 0, n = dit.size(); i != n; ++i)
@@ -429,13 +444,20 @@ StableDocIterator::StableDocIterator(const DocIterator & dit)
 }
 
 
-DocIterator
-StableDocIterator::asDocIterator(InsetBase * inset) const
+DocIterator StableDocIterator::asDocIterator(InsetBase * inset) const
 {
        // this function re-creates the cache of inset pointers
        //lyxerr << "converting:\n" << *this << endl;
        DocIterator dit = DocIterator(*inset);
        for (size_t i = 0, n = data_.size(); i != n; ++i) {
+               if (inset == 0) {
+                       // FIXME
+                       lyxerr << "Should not happen, but does e.g. after C-n C-l C-z S-C-z"
+                               << endl << "dit: " << dit << endl
+                               << " lastpos: " << dit.lastpos() << endl;
+                       //break;
+                       BOOST_ASSERT(false);
+               }
                dit.push_back(data_[i]);
                dit.back().inset_ = inset;
                if (i + 1 != n)