]> git.lyx.org Git - features.git/blobdiff - src/mathed/MathAutoCorrect.cpp
Allow to undo partly math autocorrect
[features.git] / src / mathed / MathAutoCorrect.cpp
index be5aeb42d0430c127179379784f8275431b83437..77e5fefbd4e7b541d3bce77d6795ae6ffd0b325e 100644 (file)
@@ -90,8 +90,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;