]> git.lyx.org Git - features.git/blobdiff - src/cursor_slice.C
more IU
[features.git] / src / cursor_slice.C
index 7094014d89c1cd6cc1a50256ca38ab9f313bc13f..4427fc3984f0647fe7b2644f306e475d1b8996e3 100644 (file)
 #include "debug.h"
 
 #include "mathed/math_inset.h"
+#include "mathed/math_data.h"
+
 #include "insets/updatableinset.h"
 
+
 #include <boost/assert.hpp>
 
 using std::endl;
@@ -181,3 +184,64 @@ std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
 ;
        return os;
 }
+
+
+
+
+void increment(CursorBase & it)
+{
+       CursorSlice & top = it.back();
+       MathArray   & ar  = top.asMathInset()->cell(top.idx_);
+
+       // move into the current inset if possible
+       // it is impossible for pos() == size()!
+       MathInset * n = 0;
+       if (top.pos_ != ar.size())
+               n = (ar.begin() + top.pos_)->nucleus();
+       if (n && n->isActive()) {
+               it.push_back(CursorSlice(n));
+               return;
+       }
+
+       // otherwise move on one cell back if possible
+       if (top.pos_ < ar.size()) {
+               // pos() == size() is valid!
+               ++top.pos_;
+               return;
+       }
+
+       // otherwise try to move on one cell if possible
+       while (top.idx_ + 1 < top.asMathInset()->nargs()) {
+               // idx() == nargs() is _not_ valid!
+               ++top.idx_;
+               if (top.asMathInset()->validCell(top.idx_)) {
+                       top.pos_ = 0;
+                       return;
+               }
+       }
+
+       // otherwise leave array, move on one back
+       // this might yield pos() == size(), but that's a ok.
+       it.pop_back();
+       // it certainly invalidates top
+       ++it.back().pos_;
+}
+
+
+CursorBase ibegin(InsetBase * p)
+{
+       CursorBase it;
+       it.push_back(CursorSlice(p));
+       return it;
+}
+
+
+CursorBase iend(InsetBase * p)
+{
+       CursorBase it;
+       it.push_back(CursorSlice(p));
+       CursorSlice & top = it.back();
+       top.idx_ = top.asMathInset()->nargs() - 1;
+       top.pos_ = top.asMathInset()->cell(top.idx_).size();
+       return it;
+}