+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)
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();
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
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);
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;
}