diff --git a/src/ChangeLog b/src/ChangeLog index 5117a5a8fd..faf4cd5b5f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2005-10-09 Georg Baum + + * text3.C (mathDispatch, dispatch): Dont' record undo steps that don't + change anything. + 2005-10-11 Martin Vermeer * BufferView_pimpl.C: comment layout change diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 37ef546e50..d0bb6cea54 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,8 @@ +2005-10-09 Georg Baum + + * math_nestinset.C (doDispatch): Don't record undo steps when + inserting characters of a macro name (see comment) + 2005-10-04 Georg Baum * math_macro.C (editXY): new, fix crash (bug 2060) diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index d9313471af..b12a44ad16 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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(); diff --git a/src/text3.C b/src/text3.C index 2a7b879f3f..671f7e6cc4 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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; }