]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.C
forward search in math insets. ugly. seems to work. don't ask why.
[lyx.git] / src / mathed / math_cursor.C
index 12126ff24529212e1a31eb67a0809cfa16714cdf..24e53be5706875371cc42776402f70bb20f4cf50 100644 (file)
 #pragma implementation
 #endif
 
+#include "support/lstrings.h"
+#include "support/LAssert.h"
+#include "debug.h"
+#include "LColor.h"
+#include "Painter.h"
 #include "math_cursor.h"
 #include "formulabase.h"
 #include "math_arrayinset.h"
 #include "math_braceinset.h"
+#include "math_boxinset.h"
 #include "math_casesinset.h"
 #include "math_charinset.h"
 #include "math_deliminset.h"
 #include "math_specialcharinset.h"
 #include "math_support.h"
 
-#include "debug.h"
-#include "LColor.h"
-#include "Painter.h"
-
-#include "support/lstrings.h"
-#include "support/LAssert.h"
-
 #include <algorithm>
 #include <cctype>
 
@@ -125,16 +124,22 @@ struct Selection
        }
 
        void paste(MathCursor & cursor) const
-       {       
-               idx_type idx;
-               MathGridInset * p = cursor.enclosingGrid(idx);
-               col_type const numcols = min(data_.ncols(), p->ncols() - p->col(idx));
-               row_type const numrows = min(data_.nrows(), p->nrows() - p->row(idx));
-               for (row_type row = 0; row < numrows; ++row) 
-                       for (col_type col = 0; col < numcols; ++col) {
-                               idx_type i = p->index(row + p->row(idx), col + p->col(idx));
-                               p->cell(i).push_back(data_.cell(data_.index(row, col)));
-                       }
+       {
+               if (data_.nargs() == 1) {
+                       // single cell/part of cell
+                       cursor.insert(data_.cell(0));
+               } else {
+                       // mulitple cells
+                       idx_type idx;
+                       MathGridInset * p = cursor.enclosingGrid(idx);
+                       col_type const numcols = min(data_.ncols(), p->ncols() - p->col(idx));
+                       row_type const numrows = min(data_.nrows(), p->nrows() - p->row(idx));
+                       for (row_type row = 0; row < numrows; ++row) 
+                               for (col_type col = 0; col < numcols; ++col) {
+                                       idx_type i = p->index(row + p->row(idx), col + p->col(idx));
+                                       p->cell(i).push_back(data_.cell(data_.index(row, col)));
+                               }
+               }
        }
 
        // glues selection to one cell
@@ -891,30 +896,34 @@ void MathCursor::pullArg(bool goright)
 }
 
 
-void MathCursor::normalize() const
+void MathCursor::normalize()
 {
-#ifdef WITH_WARNINGS
-#warning This is evil!
-#endif
-       MathCursor * it = const_cast<MathCursor *>(this);
+       // rebreak
+       {
+               MathIterator it = ibegin(formula()->par().nucleus());
+               MathIterator et = iend(formula()->par().nucleus());
+               for ( ; it != et; ++it) 
+                       if (it.par()->asBoxInset())
+                               it.par()->asBoxInset()->rebreak();
+       }
 
        if (idx() >= par()->nargs()) {
                lyxerr << "this should not really happen - 1: "
                       << idx() << " " << par()->nargs() << "\n";
                dump("error 2");
        }
-       it->idx() = min(idx(), par()->nargs() - 1);
+       idx() = min(idx(), par()->nargs() - 1);
 
        if (pos() > size()) {
                lyxerr << "this should not really happen - 2: "
-                       << pos() << " " << size() <<  " in idx: " << it->idx()
+                       << pos() << " " << size() <<  " in idx: " << idx()
                        << " in atom: '";
                WriteStream wi(lyxerr, false);
-               it->par()->write(wi);
+               par()->write(wi);
                lyxerr << "\n";
                dump("error 4");
        }
-       it->pos() = min(pos(), size());
+       pos() = min(pos(), size());
 }
 
 
@@ -1339,7 +1348,7 @@ bool MathCursor::interpret(char c)
                // fall through in the other cases
        }
 
-       if (lastcode_ == LM_TC_TEXTRM) {
+       if (lastcode_ == LM_TC_TEXTRM || par()->asBoxInset()) {
                // suppress direct insertion of two spaces in a row
                // the still allows typing  '<space>a<space>' and deleting the 'a', but
                // it is better than nothing...
@@ -1354,7 +1363,7 @@ bool MathCursor::interpret(char c)
                        prevAtom()->asSpaceInset()->incSpace();
                        return true;
                }
-               if (mathcursor->popRight())
+               if (popRight())
                        return true;
                // if are at the very end, leave the formula
                return pos() != size();
@@ -1440,3 +1449,10 @@ void MathCursor::stripFromLastEqualSign()
 }
 
 
+void MathCursor::setSelection(cursor_type const & where, size_type n)
+{
+       selection_ = true;
+       Anchor_ = where;
+       Cursor_ = where;
+       cursor().pos_ += n;
+}