]> git.lyx.org Git - features.git/commitdiff
Fix bug 2727.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 17 Aug 2006 21:07:24 +0000 (21:07 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 17 Aug 2006 21:07:24 +0000 (21:07 +0000)
* math_scriptinset.C (notifyCursorLeaves): call recordUndoInset
before deleting a cell; if the nucleus does not have scripts
anymore, delete it and replace it by its contents at enclosing
level.
(write): output scripts even when they are empry.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14793 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_scriptinset.C

index 39fef44309610dec79947c759c707332c934cf0d..0fe75740aa0851743f2fd6b03b756feb02e76a41 100644 (file)
@@ -19,6 +19,7 @@
 #include "cursor.h"
 #include "debug.h"
 #include "funcrequest.h"
+#include "undo.h"
 
 #include <boost/assert.hpp>
 
@@ -434,10 +435,10 @@ void MathScriptInset::write(WriteStream & os) const
                        os << "{}";
        }
 
-       if (hasDown() && down().size())
+       if (hasDown() /*&& down().size()*/)
                os << "_{" << down() << '}';
 
-       if (hasUp() && up().size())
+       if (hasUp() /*&& up().size()*/)
                os << "^{" << up() << '}';
 
        if (lock_ && !os.latex())
@@ -565,14 +566,27 @@ void MathScriptInset::notifyCursorLeaves(LCursor & cur)
                // Case of two scripts. In this case, 1 = super, 2 = sub
                if (cur.idx() == 2 && cell(2).empty()) {
                        // must be a subscript...
+                       recordUndoInset(cur);
                        removeScript(false);
                } else if (cur.idx() == 1 && cell(1).empty()) {
                        // must be a superscript...
+                       recordUndoInset(cur);
                        removeScript(true);
                }
        } else if (nargs() > 1 && cur.idx() == 1 && cell(1).empty()) {
                // could be either subscript or super script
+               recordUndoInset(cur);
                removeScript(cell_1_is_up_);
+               // Let the script inset commit suicide. This is
+               // modelled on LCursor.pullArg(), but tries not to
+               // invoke notifyCursorLeaves again and does not touch
+               // cur (since the top slice will be deleted
+               // afterwards))
+               MathArray ar = cell(0);
+               LCursor tmpcur = cur;
+               tmpcur.pop();
+               tmpcur.cell().erase(tmpcur.pos());
+               tmpcur.cell().insert(tmpcur.pos(), ar);
        }
 
        //lyxerr << "MathScriptInset::notifyCursorLeaves: 2 " << cur << endl;