X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathScript.cpp;h=c146e071b15e7fc9008d1e2d99c63c420e401b1f;hb=11a6b3c4c7a031fd3776f53c9c43f62116933cea;hp=2d283696d98f6567bd98efb28bf6409c40267b63;hpb=d78b0692e26f8a41f80cac0aadeb390367603af2;p=lyx.git diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp index 2d283696d9..c146e071b1 100644 --- a/src/mathed/InsetMathScript.cpp +++ b/src/mathed/InsetMathScript.cpp @@ -10,16 +10,18 @@ #include +#include "BufferView.h" +#include "Cursor.h" +#include "DispatchResult.h" +#include "FuncRequest.h" +#include "InsetMathFont.h" #include "InsetMathScript.h" +#include "InsetMathSymbol.h" #include "MathData.h" #include "MathStream.h" #include "MathSupport.h" -#include "InsetMathSymbol.h" -#include "InsetMathFont.h" -#include "DispatchResult.h" -#include "Cursor.h" + #include "support/debug.h" -#include "FuncRequest.h" #include @@ -671,13 +673,11 @@ bool InsetMathScript::notifyCursorLeaves(Cursor & cur) if (nargs() > 2 && (!cell(1).empty() || !cell(2).empty())) { if (cell(2).empty()) { // must be a subscript... - cur.recordUndoInset(); removeScript(false); cur.updateFlags(cur.disp_.update() | Update::SinglePar); return true; } else if (cell(1).empty()) { // must be a superscript... - cur.recordUndoInset(); removeScript(true); cur.updateFlags(cur.disp_.update() | Update::SinglePar); return true; @@ -689,18 +689,30 @@ bool InsetMathScript::notifyCursorLeaves(Cursor & cur) // The script inset is removed completely. if ((nargs() == 2 && cell(1).empty()) || (nargs() == 3 && cell(1).empty() && cell(2).empty())) { - // could be either subscript or super script - cur.recordUndoInset(); + // Make undo step. We cannot use cur for this because + // it does not necessarily point to us. The BufferView + // cursor though should do. + int scriptSlice + = cur.bv().cursor().find(this); + BOOST_ASSERT(scriptSlice != -1); + Cursor & bvCur = cur.bv().cursor(); + bvCur.cutOff(scriptSlice); + bvCur.recordUndoInset(); + // Let the script inset commit suicide. This is // modelled on Cursor.pullArg(), but tries not to // invoke notifyCursorLeaves again and does not touch // cur (since the top slice will be deleted - // afterwards)) + // afterwards) MathData ar = cell(0); - Cursor tmpcur = cur; - tmpcur.pop(); - tmpcur.cell().erase(tmpcur.pos()); - tmpcur.cell().insert(tmpcur.pos(), ar); + bvCur.pop(); + bvCur.cell().erase(bvCur.pos()); + bvCur.cell().insert(bvCur.pos(), ar); + + // put cursor behind + bvCur.pos() += ar.size(); + + // redraw cur.updateFlags(cur.disp_.update() | Update::SinglePar); return true; }