]> git.lyx.org Git - lyx.git/blobdiff - src/dociterator.C
Scons: update_po target, part one: language_l10n.pot
[lyx.git] / src / dociterator.C
index 4955cbf910951b472f91095859244187c19755d4..ad96095022b2ebbc6b2340bd8bee89b2ff565897 100644 (file)
@@ -15,7 +15,6 @@
 
 #include "debug.h"
 #include "lyxtext.h"
-#include "lyxrow.h"
 #include "paragraph.h"
 
 #include "mathed/MathData.h"
@@ -26,6 +25,9 @@
 #include <boost/assert.hpp>
 #include <boost/current_function.hpp>
 
+
+namespace lyx {
+
 using std::endl;
 
 
@@ -76,7 +78,13 @@ InsetBase * DocIterator::prevInset()
        if (pos() == 0)
                return 0;
        if (inMathed())
-               return prevAtom().nucleus();
+               if (cell().empty())
+                       // FIXME: this should not happen but it does.
+                       // See bug 3189
+                       // http://bugzilla.lyx.org/show_bug.cgi?id=3189
+                       return 0;
+               else
+                       return prevAtom().nucleus();
        return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0;
 }
 
@@ -87,7 +95,13 @@ InsetBase const * DocIterator::prevInset() const
        if (pos() == 0)
                return 0;
        if (inMathed())
-               return prevAtom().nucleus();
+               if (cell().empty())
+                       // FIXME: this should not happen but it does.
+                       // See bug 3189
+                       // http://bugzilla.lyx.org/show_bug.cgi?id=3189
+                       return 0;
+               else
+                       return prevAtom().nucleus();
        return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0;
 }
 
@@ -167,27 +181,13 @@ Paragraph const & DocIterator::paragraph() const
 }
 
 
-Row & DocIterator::textRow()
-{
-       BOOST_ASSERT(!paragraph().rows().empty());
-       return paragraph().getRow(pos(), boundary_);
-}
-
-
-Row const & DocIterator::textRow() const
-{
-       BOOST_ASSERT(!paragraph().rows().empty());
-       return paragraph().getRow(pos(), boundary_);
-}
-
-
-DocIterator::pit_type DocIterator::lastpit() const
+pit_type DocIterator::lastpit() const
 {
        return inMathed() ? 0 : text()->paragraphs().size() - 1;
 }
 
 
-DocIterator::pos_type DocIterator::lastpos() const
+pos_type DocIterator::lastpos() const
 {
        return inMathed() ? cell().size() : paragraph().size();
 }
@@ -246,18 +246,6 @@ MathArray & DocIterator::cell()
 }
 
 
-bool DocIterator::inMathed() const
-{
-       return !empty() && inset().inMathed();
-}
-
-
-bool DocIterator::inTexted() const
-{
-       return !empty() && !inset().inMathed();
-}
-
-
 LyXText * DocIterator::innerText()
 {
        BOOST_ASSERT(!empty());
@@ -298,11 +286,12 @@ void DocIterator::forwardPos(bool ignorecollapsed)
                return;
        }
 
+       InsetBase * const nextinset = nextInset();
        // jump over collapsables if they are collapsed
        // FIXME: the check for asInsetMath() shouldn't be necessary
        // but math insets do not return a sensible editable() state yet.
-       if (ignorecollapsed && nextInset() && (!nextInset()->asInsetMath()
-           && nextInset()->editable() != InsetBase::HIGHLY_EDITABLE)) {
+       if (ignorecollapsed && nextinset && (!nextinset->asInsetMath()
+           && nextinset->editable() != InsetBase::HIGHLY_EDITABLE)) {
                ++top().pos();
                return;
        }
@@ -411,26 +400,19 @@ void DocIterator::forwardPar()
 {
        forwardPos();
 
-#if 0
-       DocIterator cmp(*this);
-#endif
-
        while (!empty() && (!inTexted() || pos() != 0)) {
                if (inTexted()) {
                        pos_type const lastp = lastpos();
                        Paragraph const & par = paragraph();
                        pos_type & pos = top().pos();
-                       while (pos < lastp && !par.isInset(pos))
-                               ++pos;
+                       if (par.insetlist.empty())
+                               pos = lastp;
+                       else
+                               while (pos < lastp && !par.isInset(pos))
+                                       ++pos;
                }
                forwardPos();
        }
-
-#if 0
-       while (!cmp.empty() && (!cmp.inTexted() || cmp.pos() != 0))
-               cmp.forwardPos();
-       BOOST_ASSERT(cmp == *this);
-#endif
 }
 
 
@@ -445,8 +427,19 @@ void DocIterator::forwardChar()
 void DocIterator::forwardInset()
 {
        forwardPos();
-       while (!empty() && (pos() == lastpos() || nextInset() == 0))
+
+       while (!empty() && !nextInset()) {
+               if (inTexted()) {
+                       pos_type const lastp = lastpos();
+                       Paragraph const & par = paragraph();
+                       pos_type & pos = top().pos();
+                       while (pos < lastp && !par.isInset(pos))
+                               ++pos;
+                       if (pos < lastp)
+                               break;
+               }
                forwardPos();
+       }
 }
 
 
@@ -592,3 +585,6 @@ bool operator==(StableDocIterator const & dit1, StableDocIterator const & dit2)
 {
        return dit1.data_ == dit2.data_;
 }
+
+
+} // namespace lyx