]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/formulabase.C
Fix.
[lyx.git] / src / mathed / formulabase.C
index 758dc0c6115e10e7dbed979e0c1db0500c28f938..1ab3bf9c90d704652d9e7bc204718d22ab788c53 100644 (file)
@@ -18,9 +18,6 @@
 #include "Lsstream.h"
 #include "support/LAssert.h"
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include "formula.h"
 #include "formulamacro.h"
@@ -234,7 +231,7 @@ void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
 void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
 {
        if (!mathcursor) {
-               lyxerr << "toggleInsetCursor impossible" << endl;
+               lyxerr[Debug::MATHED] << "toggleInsetCursor impossible" << endl;
                return;
        }
        //lyxerr << "toggleInsetCursor: " << isCursorVisible() << endl;
@@ -356,7 +353,7 @@ Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd)
        //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
 
        if (!mathcursor || mathcursor->formula() != this) {
-               lyxerr << "re-create cursor" << endl;
+               lyxerr[Debug::MATHED] << "re-create cursor" << endl;
                releaseMathCursor(bv);
                mathcursor = new MathCursor(this, cmd.x == 0);
                metrics(bv);
@@ -420,6 +417,9 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        //      << " y: '" << cmd.y
        //      << "' button: " << cmd.button() << endl;
 
+       // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
+       bool remove_inset = false;
+
        switch (cmd.action) {
                case LFUN_MOUSE_PRESS:
                        return lfunMousePress(cmd);
@@ -536,7 +536,7 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        case LFUN_PRIOR:
        case LFUN_BEGINNINGBUFSEL:
        case LFUN_BEGINNINGBUF:
-               result = FINISHED_UP;
+               result = FINISHED;
                updateLocal(bv, false);
                break;
 
@@ -544,7 +544,7 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        case LFUN_NEXT:
        case LFUN_ENDBUFSEL:
        case LFUN_ENDBUF:
-               result = FINISHED_DOWN;
+               result = FINISHED_RIGHT;
                updateLocal(bv, false);
                break;
 
@@ -560,16 +560,26 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
 
        case LFUN_DELETE_WORD_BACKWARD:
        case LFUN_BACKSPACE:
-               bv->lockedInsetStoreUndo(Undo::DELETE);
-               mathcursor->backspace();
+               bv->lockedInsetStoreUndo(Undo::EDIT);
+               if (mathcursor->backspace()) {
+                       result = DISPATCHED;
+               } else {
+                       result = FINISHED;
+                       remove_inset = true;
+               }
                updateLocal(bv, true);
                break;
 
        case LFUN_DELETE_WORD_FORWARD:
        case LFUN_DELETE:
-               bv->lockedInsetStoreUndo(Undo::DELETE);
-               mathcursor->erase();
-               bv->updateInset(this, true);
+               bv->lockedInsetStoreUndo(Undo::EDIT);
+               if (mathcursor->erase()) {
+                       result = DISPATCHED;
+               } else {
+                       result = FINISHED;
+                       remove_inset = true;
+               }
+               updateLocal(bv, true);
                break;
 
        //    case LFUN_GETXY:
@@ -829,6 +839,8 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        } else {
                releaseMathCursor(bv);
                bv->unlockInset(this);
+               if (remove_inset)
+                       bv->owner()->dispatch(FuncRequest(LFUN_DELETE));
        }
 
        return result;  // original version