]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathAutoCorrect.cpp
Display equation/theorem numbers in insert cross reference dialog.
[lyx.git] / src / mathed / MathAutoCorrect.cpp
index be5aeb42d0430c127179379784f8275431b83437..5d5a7d098c4782057603ac8e373f64529052cbae 100644 (file)
@@ -10,8 +10,9 @@
 
 #include <config.h>
 
-#include "Cursor.h"
 #include "MathAutoCorrect.h"
+
+#include "Cursor.h"
 #include "MathData.h"
 #include "InsetMath.h"
 #include "MathSupport.h"
@@ -90,8 +91,17 @@ bool Correction::correct(Cursor & cur, char_type c) const
        LYXERR(Debug::MATHED, "match found! subst in " << cur.cell()
                << " from: '" << from1_ << "' to '" << to_ << '\'');
 
-       cur.cell().erase(cur.pos() - n, cur.pos());
-       cur.pos() -= n;
+       /* To allow undoing the completion, we proceed in 4 steps
+        * - inset the raw character
+        * - split undo group so that we have two separate undo actions
+        * - record undo, delete the character we just entered and the from1_ part
+        * - finally, do the insertion of the correction.
+        */
+       cur.insert(c);
+       cur.splitUndoGroup();
+       cur.recordUndoSelection();
+       cur.cell().erase(cur.pos() - n - 1, cur.pos());
+       cur.pos() -= n + 1;
 
        cur.insert(to_);
        return true;