]> git.lyx.org Git - features.git/commitdiff
Fix undo of entering \hline
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 8 Apr 2012 17:15:49 +0000 (19:15 +0200)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 8 Apr 2012 17:15:49 +0000 (19:15 +0200)
It was broken with 6d75800f5d23 as noticed by Enrico. The fix is to use undo
groups (thanks Jean-Marc).

src/Cursor.cpp
src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathNest.cpp
src/mathed/MathData.cpp

index 7a13e1c3c9a5229997f8e8295c533d5dd540a32f..be042940a081b3806ca129c6f0d657f8f081b99e 100644 (file)
@@ -1599,8 +1599,11 @@ bool Cursor::macroModeClose()
 
        docstring const name = s.substr(1);
        InsetMathNest * const in = inset().asInsetMath()->asNestInset();
-       if (in && in->interpretString(*this, s))
+       if (in && in->interpretString(*this, s)) {
+               // end undo group that was opened before in was created
+               endUndoGroup();
                return true;
+       }
        MathAtom atom = buffer()->getMacro(name, *this, false) ?
                MathAtom(new MathMacro(buffer(), name)) : createInsetMath(name, buffer());
 
@@ -1633,7 +1636,9 @@ bool Cursor::macroModeClose()
                else
                        insert(selection);
        }
-       
+
+       // end undo group that was opened before in was created
+       endUndoGroup();
        return true;
 }
 
index ed77f71f851be12a46fa959b5b0f9c7e81d0defc..87f7d4b4f533a8d7f5f214813bf683eb51b3df4a 100644 (file)
@@ -184,6 +184,7 @@ bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
                FuncStatus status;
                if (getStatus(cur, fr, status)) {
                        if (status.enabled()) {
+                               cur.recordUndoInset();
                                rowinfo_[cur.row()].lines_++;
                                return true;
                        }
index c2f4fc16ba5deabdc0e1a9ae2d4e610c038e0927..860d265e53c205cf6d21b2827d15889957292d9c 100644 (file)
@@ -848,10 +848,14 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_SELF_INSERT:
                if (cmd.argument().size() != 1) {
+                       // use a group because interpretString() might
+                       // record an extra undo step
+                       cur.beginUndoGroup();
                        cur.recordUndoSelection();
                        docstring const arg = cmd.argument();
                        if (!interpretString(cur, arg))
                                cur.insert(arg);
+                       cur.endUndoGroup();
                        break;
                }
                // Don't record undo steps if we are in macro mode and thus
@@ -1663,6 +1667,8 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
                                cur.cell().erase(cur.pos());
                                cur.plainInsert(MathAtom(
                                        new InsetMathBig(name.substr(1), delim)));
+                               // end undo group that was opened before p was created
+                               cur.endUndoGroup();
                                return true;
                        }
                }
@@ -1706,9 +1712,12 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
                bool reduced = cap::reduceSelectionToOneCell(cur);
                if (reduced || !cur.selection()) {
                        docstring const safe = cap::grabAndEraseSelection(cur);
-                       if (!cur.inRegexped())
+                       if (!cur.inRegexped()) {
+                               // open a group because interpretString() might
+                               // record an extra undo step when finalizing
+                               cur.beginUndoGroup();
                                cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
-                       else
+                       else
                                cur.niceInsert(createInsetMath("backslash", buf));
                }
                return true;
index 8fcf7466e34c825cfbe07f7badab5ca09befa1ee..a4a11bb1361514ba830750d97c7e6827c1782c2a 100644 (file)
@@ -28,8 +28,6 @@
 #include "CoordCache.h"
 #include "Cursor.h"
 
-#include "mathed/InsetMathUnknown.h"
-
 #include "support/debug.h"
 #include "support/docstream.h"