]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathScript.cpp
Fix bug 5802 (http://bugzilla.lyx.org/show_bug.cgi?id=5802)
[lyx.git] / src / mathed / InsetMathScript.cpp
index c146e071b15e7fc9008d1e2d99c63c420e401b1f..8a6c25808022a14835ffb6bdb344a848077eb733 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -23,7 +23,7 @@
 
 #include "support/debug.h"
 
-#include <boost/assert.hpp>
+#include "support/lassert.h"
 
 #include <ostream>
 
@@ -45,7 +45,7 @@ InsetMathScript::InsetMathScript(bool up)
 InsetMathScript::InsetMathScript(MathAtom const & at, bool up)
        : InsetMathNest(2), cell_1_is_up_(up), limits_(0)
 {
-       BOOST_ASSERT(nargs() >= 1);
+       LASSERT(nargs() >= 1, /**/);
        cell(0).push_back(at);
 }
 
@@ -88,7 +88,7 @@ MathData const & InsetMathScript::down() const
 {
        if (nargs() == 3)
                return cell(2);
-       BOOST_ASSERT(nargs() > 1);
+       LASSERT(nargs() > 1, /**/);
        return cell(1);
 }
 
@@ -97,21 +97,21 @@ MathData & InsetMathScript::down()
 {
        if (nargs() == 3)
                return cell(2);
-       BOOST_ASSERT(nargs() > 1);
+       LASSERT(nargs() > 1, /**/);
        return cell(1);
 }
 
 
 MathData const & InsetMathScript::up() const
 {
-       BOOST_ASSERT(nargs() > 1);
+       LASSERT(nargs() > 1, /**/);
        return cell(1);
 }
 
 
 MathData & InsetMathScript::up()
 {
-       BOOST_ASSERT(nargs() > 1);
+       LASSERT(nargs() > 1, /**/);
        return cell(1);
 }
 
@@ -245,7 +245,7 @@ int InsetMathScript::dy1(BufferView const & bv) const
 
 int InsetMathScript::dx0(BufferView const & bv) const
 {
-       BOOST_ASSERT(hasDown());
+       LASSERT(hasDown(), /**/);
        Dimension const dim = dimension(bv);
        return hasLimits() ? (dim.wid - down().dimension(bv).width()) / 2 : nwid(bv);
 }
@@ -253,7 +253,7 @@ int InsetMathScript::dx0(BufferView const & bv) const
 
 int InsetMathScript::dx1(BufferView const & bv) const
 {
-       BOOST_ASSERT(hasUp());
+       LASSERT(hasUp(), /**/);
        Dimension const dim = dimension(bv);
        return hasLimits() ? (dim.wid - up().dimension(bv).width()) / 2 : nwid(bv) + nker(&bv);
 }
@@ -462,7 +462,7 @@ Inset::idx_type InsetMathScript::idxOfScript(bool up) const
                return (cell_1_is_up_ == up) ? 1 : 0;
        if (nargs() == 3)
                return up ? 1 : 2;
-       BOOST_ASSERT(false);
+       LASSERT(false, /**/);
        // Silence compiler
        return 0;
 }
@@ -525,6 +525,8 @@ bool InsetMathScript::idxUpDown(Cursor & cur, bool up) const
 
 void InsetMathScript::write(WriteStream & os) const
 {
+       MathEnsurer ensurer(os);
+
        if (nuc().size()) {
                os << nuc();
                //if (nuc().back()->takesLimits()) {
@@ -660,9 +662,9 @@ void InsetMathScript::infoize2(odocstream & os) const
 }
 
 
-bool InsetMathScript::notifyCursorLeaves(Cursor & cur)
+bool InsetMathScript::notifyCursorLeaves(Cursor const & old, Cursor & cur)
 {
-       InsetMathNest::notifyCursorLeaves(cur);
+       InsetMathNest::notifyCursorLeaves(old, cur);
 
        //LYXERR0("InsetMathScript::notifyCursorLeaves: 1 " << cur);
 
@@ -690,14 +692,13 @@ bool InsetMathScript::notifyCursorLeaves(Cursor & cur)
        if ((nargs() == 2 && cell(1).empty())
            || (nargs() == 3 && cell(1).empty() && cell(2).empty())) {
                // Make undo step. We cannot use cur for this because
-               // it does not necessarily point to us. The BufferView
-               // cursor though should do.
-               int scriptSlice
-               = cur.bv().cursor().find(this);
-               BOOST_ASSERT(scriptSlice != -1);
-               Cursor & bvCur = cur.bv().cursor();
-               bvCur.cutOff(scriptSlice);
-               bvCur.recordUndoInset();
+               // it does not necessarily point to us anymore. But we
+               // should be on top of the cursor old.
+               Cursor insetCur = old;
+               int scriptSlice = insetCur.find(this);
+               LASSERT(scriptSlice != -1, /**/);
+               insetCur.cutOff(scriptSlice);
+               insetCur.recordUndoInset();
 
                // Let the script inset commit suicide. This is
                // modelled on Cursor.pullArg(), but tries not to
@@ -705,12 +706,9 @@ bool InsetMathScript::notifyCursorLeaves(Cursor & cur)
                // cur (since the top slice will be deleted
                // afterwards)
                MathData ar = cell(0);
-               bvCur.pop();
-               bvCur.cell().erase(bvCur.pos());
-               bvCur.cell().insert(bvCur.pos(), ar);
-
-               // put cursor behind
-               bvCur.pos() += ar.size();
+               insetCur.pop();
+               insetCur.cell().erase(insetCur.pos());
+               insetCur.cell().insert(insetCur.pos(), ar);
 
                // redraw
                cur.updateFlags(cur.disp_.update() | Update::SinglePar);