The following patch fixes this bug for me. However I have questions
about whether I did it right.

There are 3 mostly independent parts in the patch:

- in MathScriptInset::notifyCursorLeave, there were no recordUndoInset
  calls. This fix seems safe and obvious to me

- when doing record undo, the math cell is stored as a string.
  However, MathScriptInset::write omits empty scripts. I changed this
  in the script, but I do not know whether there are bad side effects.
  An alternative would be to add a keepempty member to WriteStream,
  which would be set to true when in asString.

- the part in undo is not really related to the bug (it could be
  omitted): it ensures that the cursor is set correctly after undoing
  an recordUndoInset undo.

Andre', if you are reading, I'd really appreciate your input.

JMarc

Index: src/mathed/math_scriptinset.C
===================================================================
--- src/mathed/math_scriptinset.C	(revision 14670)
+++ src/mathed/math_scriptinset.C	(working copy)
@@ -19,6 +19,7 @@
 #include "cursor.h"
 #include "debug.h"
 #include "funcrequest.h"
+#include "undo.h"
 
 #include <boost/assert.hpp>
 
@@ -432,10 +433,10 @@ void MathScriptInset::write(WriteStream 
 			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())
@@ -563,15 +564,18 @@ void MathScriptInset::notifyCursorLeaves
 		// 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_);
-}
+	}
 
 	//lyxerr << "MathScriptInset::notifyCursorLeaves: 2 " << cur << endl;
 }
Index: src/undo.C
===================================================================
--- src/undo.C	(revision 14670)
+++ src/undo.C	(working copy)
@@ -251,7 +251,9 @@ void recordUndoInset(LCursor & cur, Undo
 {
 	LCursor c = cur;
 	c.pop();
-	recordUndo(c, kind);
+	Buffer * buf = cur.bv().buffer();
+	doRecordUndo(kind, c, c.pit(), c.pit(),	cur.bv().cursor(),
+		     buf->params(), false, buf->undostack());
 }
 
 

Reply via email to