X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMathAutoCorrect.cpp;h=5d5a7d098c4782057603ac8e373f64529052cbae;hb=c609e9cbcf;hp=be5aeb42d0430c127179379784f8275431b83437;hpb=144e7d715938af7cadd9073f4afc30f3744a226a;p=lyx.git diff --git a/src/mathed/MathAutoCorrect.cpp b/src/mathed/MathAutoCorrect.cpp index be5aeb42d0..5d5a7d098c 100644 --- a/src/mathed/MathAutoCorrect.cpp +++ b/src/mathed/MathAutoCorrect.cpp @@ -10,8 +10,9 @@ #include -#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;