]> git.lyx.org Git - features.git/commitdiff
fix invalid cursor after math undo
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Wed, 12 Oct 2005 18:40:22 +0000 (18:40 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Wed, 12 Oct 2005 18:40:22 +0000 (18:40 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10547 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/mathed/ChangeLog
src/mathed/math_nestinset.C
src/text3.C

index 5117a5a8fd13e536b65db1ef7b9c1bd29f3b5cac..faf4cd5b5f323a9fbe5022ee2339561929453ea3 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-09  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * text3.C (mathDispatch, dispatch): Dont' record undo steps that don't
+       change anything.
+
 2005-10-11  Martin Vermeer  <martin.vermeer@hut.fi>
 
        * BufferView_pimpl.C: comment layout change
index 37ef546e50f291797d012591a8024a48b0803d37..d0bb6cea5434b9b77ac75a37b132a8e96f2d269c 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-09  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * math_nestinset.C (doDispatch): Don't record undo steps when
+       inserting characters of a macro name (see comment)
+
 2005-10-04  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * math_macro.C (editXY): new, fix crash (bug 2060)
index d9313471afa7e9c15090e123d95916cb644b8b12..b12a44ad1672106405f8a2ce88a358d41adbf2ee 100644 (file)
@@ -651,11 +651,22 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_SELFINSERT:
-               recordUndo(cur);
                if (cmd.argument.size() != 1) {
+                       recordUndo(cur);
                        cur.insert(cmd.argument);
                        break;
                }
+               // Don't record undo steps if we are in macro mode and
+               // cmd.argument is the next character of the macro name.
+               // Otherwise we'll get an invalid cursor if we undo after
+               // the macro was finished and the macro is a known command,
+               // e.g. sqrt. LCursor::macroModeClose replaces in this case
+               // the MathUnknownInset with name "frac" by an empty
+               // MathFracInset -> a pos value > 0 is invalid.
+               // A side effect is that an undo before the macro is finished
+               // undoes the complete macro, not only the last character.
+               if (!cur.inMacroMode())
+                       recordUndo(cur);
                if (!interpret(cur, cmd.argument[0])) {
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
                        cur.undispatched();
index 2a7b879f3f9ab943abcbde5843addee96d37514d..671f7e6cc4cbbaca2af6d090b701478b01f77533 100644 (file)
@@ -136,17 +136,20 @@ namespace {
 
                if (sel.empty()) {
                        const int old_pos = cur.pos();
-                       cur.insert(new MathHullInset);
+                       cur.insert(new MathHullInset("simple"));
                        BOOST_ASSERT(old_pos == cur.pos());
                        cur.nextInset()->edit(cur, true);
-                       cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
                        // don't do that also for LFUN_MATH_MODE
                        // unless you want end up with always changing
                        // to mathrm when opening an inlined inset --
                        // I really hate "LyXfunc overloading"...
                        if (display)
                                cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
-                       cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
+                       // Avoid an unnecessary undo step if cmd.argument
+                       // is empty
+                       if (!cmd.argument.empty())
+                               cur.dispatch(FuncRequest(LFUN_INSERT_MATH,
+                                                        cmd.argument));
                } else {
                        // create a macro if we see "\\newcommand"
                        // somewhere, and an ordinary formula
@@ -155,9 +158,8 @@ namespace {
                        if (sel.find("\\newcommand") == string::npos
                            && sel.find("\\def") == string::npos)
                        {
-                               cur.insert(new MathHullInset);
+                               cur.insert(new MathHullInset("simple"));
                                cur.dispatch(FuncRequest(LFUN_RIGHT));
-                               cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
                                cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
                        } else {
                                istringstream is(sel);
@@ -1271,9 +1273,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_INSERT_MATH:
        case LFUN_INSERT_MATRIX:
        case LFUN_MATH_DELIM: {
-               cur.insert(new MathHullInset);
+               cur.insert(new MathHullInset("simple"));
                cur.dispatch(FuncRequest(LFUN_RIGHT));
-               cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
                cur.dispatch(cmd);
                break;
        }