]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.C
fix for the first item on Martin's list
[lyx.git] / src / mathed / math_cursor.C
index 2698c5bed3fa8cd72e072c5a7d47c9c2fde09905..e62ac1920d6f343362eaed166eae004ff5ad6eff 100644 (file)
@@ -38,6 +38,7 @@
 #include "math_hullinset.h"
 #include "math_iterator.h"
 #include "math_macroarg.h"
+#include "math_macrotemplate.h"
 #include "math_mathmlstream.h"
 #include "math_parser.h"
 #include "math_replace.h"
@@ -202,14 +203,9 @@ void MathCursor::pushRight(MathAtom & t)
 
 bool MathCursor::popLeft()
 {
-       //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " left\n";
+       //cerr << "Leaving atom to the left\n";
        if (Cursor_.size() <= 1)
                return false;
-       if (par()->asScriptInset()) {
-               par()->asScriptInset()->removeEmptyScripts();
-               if (par()->asScriptInset()->empty())
-                       plainErase();
-       }
        Cursor_.pop_back();
        return true;
 }
@@ -220,11 +216,6 @@ bool MathCursor::popRight()
        //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n";
        if (Cursor_.size() <= 1)
                return false;
-       if (par()->asScriptInset()) {
-               par()->asScriptInset()->removeEmptyScripts();
-               if (par()->asScriptInset()->empty())
-                       plainErase();
-       }
        Cursor_.pop_back();
        posRight();
        return true;
@@ -934,8 +925,18 @@ void MathCursor::pullArg(bool goright)
 }
 
 
+void MathCursor::touch()
+{
+       cursor_type::const_iterator it = Cursor_.begin();
+       cursor_type::const_iterator et = Cursor_.end();
+       for ( ; it != et; ++it)
+               it->xcell().touch();
+}
+
+
 void MathCursor::normalize()
 {
+#if 0
        // rebreak
        {
                MathIterator it = ibegin(formula()->par().nucleus());
@@ -944,6 +945,7 @@ void MathCursor::normalize()
                        if (it.par()->asBoxInset())
                                it.par()->asBoxInset()->rebreak();
        }
+#endif
 
        if (idx() >= par()->nargs()) {
                lyxerr << "this should not really happen - 1: "
@@ -962,6 +964,19 @@ void MathCursor::normalize()
                dump("error 4");
        }
        pos() = min(pos(), size());
+
+       // remove empty scripts if possible
+       for (pos_type i = 0; i < size(); ++i) {
+               MathScriptInset * p = array().at(i)->asScriptInset();
+               if (p) {
+                       p->removeEmptyScripts();
+                       if (p->empty())
+                               array().erase(i);
+               }
+       }
+
+       // fix again position
+       pos() = min(pos(), size());
 }
 
 
@@ -1213,8 +1228,9 @@ bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhig
        while (1) {
                // avoid invalid nesting when selecting
                if (!selection_ || positionable(it.cursor(), Anchor_)) {
-                       int xo = it.position().xpos();
-                       int yo = it.position().ypos();
+                       MathCursorPos const & top = it.position();
+                       int xo = top.xpos();
+                       int yo = top.ypos();
                        if (xlow - 2 <= xo && xo <= xhigh + 2 &&
                                        ylow - 2 <= yo && yo <= yhigh + 2)
                        {
@@ -1359,7 +1375,9 @@ bool MathCursor::interpret(char c)
        if (inMacroArgMode()) {
                --pos();
                plainErase();
-               if ('1' <= c && c <= '9')
+               int n = c - '0';
+               MathMacroTemplate * p = formula()->par()->asMacroTemplate();
+               if (p && 1 <= n && n <= p->numargs())
                        insert(MathAtom(new MathMacroArgument(c - '0')));
                else {
                        insert(MathAtom(new MathSpecialCharInset('#')));
@@ -1393,7 +1411,7 @@ bool MathCursor::interpret(char c)
 
                if (c == '\\')
                        insert(c, LM_TC_TEX);
-               else
+               else if (c != ' ')
                        insert(c, lastcode_);
 
                return true;