fix invalid cursor after math undo

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10547 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2005-10-12 18:40:22 +00:00
parent ad41d5f8e7
commit a2b40d9038
4 changed files with 30 additions and 8 deletions

View 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> 2005-10-11 Martin Vermeer <martin.vermeer@hut.fi>
* BufferView_pimpl.C: comment layout change * BufferView_pimpl.C: comment layout change

View 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> 2005-10-04 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* math_macro.C (editXY): new, fix crash (bug 2060) * math_macro.C (editXY): new, fix crash (bug 2060)

View File

@ -651,11 +651,22 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
break; break;
case LFUN_SELFINSERT: case LFUN_SELFINSERT:
recordUndo(cur);
if (cmd.argument.size() != 1) { if (cmd.argument.size() != 1) {
recordUndo(cur);
cur.insert(cmd.argument); cur.insert(cmd.argument);
break; 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])) { if (!interpret(cur, cmd.argument[0])) {
cmd = FuncRequest(LFUN_FINISHED_RIGHT); cmd = FuncRequest(LFUN_FINISHED_RIGHT);
cur.undispatched(); cur.undispatched();

View File

@ -136,17 +136,20 @@ namespace {
if (sel.empty()) { if (sel.empty()) {
const int old_pos = cur.pos(); const int old_pos = cur.pos();
cur.insert(new MathHullInset); cur.insert(new MathHullInset("simple"));
BOOST_ASSERT(old_pos == cur.pos()); BOOST_ASSERT(old_pos == cur.pos());
cur.nextInset()->edit(cur, true); cur.nextInset()->edit(cur, true);
cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
// don't do that also for LFUN_MATH_MODE // don't do that also for LFUN_MATH_MODE
// unless you want end up with always changing // unless you want end up with always changing
// to mathrm when opening an inlined inset -- // to mathrm when opening an inlined inset --
// I really hate "LyXfunc overloading"... // I really hate "LyXfunc overloading"...
if (display) if (display)
cur.dispatch(FuncRequest(LFUN_MATH_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 { } else {
// create a macro if we see "\\newcommand" // create a macro if we see "\\newcommand"
// somewhere, and an ordinary formula // somewhere, and an ordinary formula
@ -155,9 +158,8 @@ namespace {
if (sel.find("\\newcommand") == string::npos if (sel.find("\\newcommand") == string::npos
&& sel.find("\\def") == 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_RIGHT));
cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel)); cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
} else { } else {
istringstream is(sel); istringstream is(sel);
@ -1271,9 +1273,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_INSERT_MATH: case LFUN_INSERT_MATH:
case LFUN_INSERT_MATRIX: case LFUN_INSERT_MATRIX:
case LFUN_MATH_DELIM: { case LFUN_MATH_DELIM: {
cur.insert(new MathHullInset); cur.insert(new MathHullInset("simple"));
cur.dispatch(FuncRequest(LFUN_RIGHT)); cur.dispatch(FuncRequest(LFUN_RIGHT));
cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
cur.dispatch(cmd); cur.dispatch(cmd);
break; break;
} }