]> 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 98e772ccb479af2ccfea8375f3ec76d76f0e9df9..e62ac1920d6f343362eaed166eae004ff5ad6eff 100644 (file)
@@ -203,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;
 }
@@ -221,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;
@@ -974,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());
 }