]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_scriptinset.C
float2string #4 (Spacing)
[lyx.git] / src / mathed / math_scriptinset.C
index f884901e52eab1cb1ee018bb1e8afffd63d8a5ef..cf23765572186e00b490bb7606b1210e4e5316e8 100644 (file)
@@ -42,12 +42,12 @@ MathScriptInset::MathScriptInset(bool up)
 MathScriptInset::MathScriptInset(MathAtom const & at, bool up)
        : MathNestInset(2), cell_1_is_up_(up), limits_(0)
 {
+       BOOST_ASSERT(nargs() >= 1);
        cell(0).push_back(at);
 }
 
 
-
-auto_ptr<InsetBase> MathScriptInset::clone() const
+auto_ptr<InsetBase> MathScriptInset::doClone() const
 {
        return auto_ptr<InsetBase>(new MathScriptInset(*this));
 }
@@ -83,24 +83,32 @@ bool MathScriptInset::idxLast(LCursor & cur) const
 
 MathArray const & MathScriptInset::down() const
 {
-       return nargs() == 2 ? cell(2) : cell(1);
+       if (nargs() == 3)
+               return cell(2);
+       BOOST_ASSERT(nargs() > 1);
+       return cell(1);
 }
 
 
 MathArray & MathScriptInset::down()
 {
-       return nargs() == 2 ? cell(2) : cell(1);
+       if (nargs() == 3)
+               return cell(2);
+       BOOST_ASSERT(nargs() > 1);
+       return cell(1);
 }
 
 
 MathArray const & MathScriptInset::up() const
 {
+       BOOST_ASSERT(nargs() > 1);
        return cell(1);
 }
 
 
 MathArray & MathScriptInset::up()
 {
+       BOOST_ASSERT(nargs() > 1);
        return cell(1);
 }
 
@@ -111,7 +119,7 @@ void MathScriptInset::ensure(bool up)
                // just nucleus so far
                cells_.push_back(MathArray());
                cell_1_is_up_ = up;
-       } else if (nargs() == 2 && !has(up)) { 
+       } else if (nargs() == 2 && !has(up)) {
                if (up) {
                        cells_.push_back(cell(1));
                        cell(1).clear();
@@ -296,9 +304,12 @@ bool MathScriptInset::hasLimits() const
 
 void MathScriptInset::removeScript(bool up)
 {
+       lyxerr << "MathScriptInset::removeScript: 1 up: " << up << endl;
        if (nargs() == 2) {
+               lyxerr << "MathScriptInset::removeScript: a up: " << up << endl;
                if (up == cell_1_is_up_)
                        cells_.pop_back();
+               lyxerr << "MathScriptInset::removeScript: b up: " << up << endl;
        } else if (nargs() == 3) {
                if (up == true) {
                        swap(cells_[1], cells_[2]);
@@ -306,7 +317,9 @@ void MathScriptInset::removeScript(bool up)
                } else {
                        cell_1_is_up_ = true;
                }
+               cells_.pop_back();
        }
+       lyxerr << "MathScriptInset::removeScript: 2 up: " << up << endl;
 }
 
 
@@ -318,16 +331,16 @@ bool MathScriptInset::has(bool up) const
 
 bool MathScriptInset::hasUp() const
 {
-       //lyxerr << "hasUp: " << bool(idxOfScript(true)) << endl;
        //lyxerr << "1up: " << bool(cell_1_is_up_) << endl;
+       //lyxerr << "hasUp: " << bool(idxOfScript(true)) << endl;
        return idxOfScript(true);
 }
 
 
 bool MathScriptInset::hasDown() const
 {
-       //lyxerr << "hasDown: " << bool(idxOfScript(false)) << endl;
        //lyxerr << "1up: " << bool(cell_1_is_up_) << endl;
+       //lyxerr << "hasDown: " << bool(idxOfScript(false)) << endl;
        return idxOfScript(false);
 }
 
@@ -337,7 +350,7 @@ InsetBase::idx_type MathScriptInset::idxOfScript(bool up) const
        if (nargs() == 1)
                return 0;
        if (nargs() == 2)
-               return cell_1_is_up_ == up ? 1 : 0;
+               return (cell_1_is_up_ == up) ? 1 : 0;
        if (nargs() == 3)
                return up ? 1 : 2;
        BOOST_ASSERT(false);
@@ -376,7 +389,7 @@ bool MathScriptInset::idxUpDown(LCursor & cur, bool up) const
        }
 
        // Are we 'up'?
-       if (cur.idx() == idxOfScript(true)) {
+       if (has(up) && cur.idx() == idxOfScript(true)) {
                // can't go further up
                if (up)
                        return false;
@@ -387,7 +400,7 @@ bool MathScriptInset::idxUpDown(LCursor & cur, bool up) const
        }
 
        // Are we 'down'?
-       if (cur.idx() == idxOfScript(false)) {
+       if (has(up) && cur.idx() == idxOfScript(false)) {
                // can't go further down
                if (!up)
                        return false;
@@ -539,26 +552,28 @@ void MathScriptInset::infoize2(std::ostream & os) const
 }
 
 
-void MathScriptInset::notifyCursorLeaves(idx_type idx)
+void MathScriptInset::notifyCursorLeaves(LCursor & cur)
 {
-       MathNestInset::notifyCursorLeaves(idx);
+       MathNestInset::notifyCursorLeaves(cur);
+
+       lyxerr << "MathScriptInset::notifyCursorLeaves: 1 " << cur << endl;
 
        // remove empty scripts if possible
-       if (idx == 2 && cell(2).empty()) {
-               removeScript(false); // must be a subscript...
-       } else if (idx == 1 && cell(1).empty()) {
-               if (nargs() == 2) {
-                       cell_1_is_up_ = false;
-                       cell(1) = cell(2);
-                       cells_.pop_back();
-               } else if (nargs() == 1) {
-                       cells_.pop_back();
-               }
+if (1) {
+       if (nargs() > 2 && cur.idx() == 2 && cell(2).empty()) {
+               // must be a subscript...
+               removeScript(false);
+       } else if (nargs() > 1 && cur.idx() == 1 && cell(1).empty()) {
+               // could be either subscript or super script
+               removeScript(cell_1_is_up_);
        }
 }
 
+       lyxerr << "MathScriptInset::notifyCursorLeaves: 2 " << cur << endl;
+}
+
 
-void MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
+void MathScriptInset::doDispatch(LCursor & cur, FuncRequest & cmd)
 {
        //lyxerr << "MathScriptInset: request: " << cmd << std::endl;
 
@@ -577,5 +592,5 @@ void MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                return;
        }
 
-       MathNestInset::priv_dispatch(cur, cmd);
+       MathNestInset::doDispatch(cur, cmd);
 }