]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.C
Georg Baum's vspace change
[lyx.git] / src / mathed / math_cursor.C
index ce4c12311c52601f549788e1b773ddfebf3676f6..2d3400a699c5ea23095d0320112874d657b13960 100644 (file)
 
 #include <config.h>
 
+#include "math_cursor.h"
 #include "lyxrc.h"
 #include "support/limited_stack.h"
+#include "dispatchresult.h"
 #include "debug.h"
 #include "support/std_sstream.h"
-#include "math_cursor.h"
 #include "formulabase.h"
 #include "funcrequest.h"
 #include "math_braceinset.h"
 #include "math_support.h"
 #include "math_unknowninset.h"
 
+#include <boost/assert.hpp>
 
 //#define FILEDEBUG 1
 
+using std::string;
 using std::endl;
+#ifndef CXX_GLOBAL_CSTD
 using std::isalpha;
+#endif
 using std::min;
 using std::swap;
 
@@ -431,8 +436,14 @@ bool MathCursor::backspace()
                }
        }
 
-       --pos();
-       plainErase();
+       if (hasPrevAtom() && prevAtom()->nargs() > 0) {
+               // let's require two backspaces for 'big stuff' and
+               // highlight on the first
+               left(true);
+       } else {
+               --pos();
+               plainErase();
+       }
        return true;
 }
 
@@ -614,10 +625,10 @@ void MathCursor::drawSelection(PainterInfo & pi) const
 }
 
 
-void MathCursor::handleNest(MathAtom const & a)
+void MathCursor::handleNest(MathAtom const & a, int c)
 {
        MathAtom at = a;
-       asArray(grabAndEraseSelection(), at.nucleus()->cell(0));
+       asArray(grabAndEraseSelection(), at.nucleus()->cell(c));
        insert(at);
        pushRight(prevAtom());
 }
@@ -935,28 +946,30 @@ bool MathCursor::goUpDown(bool up)
                xo = targetx_;
 
        // try neigbouring script insets
-       // try left
-       if (hasPrevAtom()) {
-               MathScriptInset const * p = prevAtom()->asScriptInset();
-               if (p && p->has(up)) {
-                       --pos();
-                       push(nextAtom());
-                       idx() = up; // the superscript has index 1
-                       pos() = size();
-                       ///lyxerr << "updown: handled by scriptinset to the left" << endl;
-                       return true;
+       if (!selection()) {
+               // try left
+               if (hasPrevAtom()) {
+                       MathScriptInset const * p = prevAtom()->asScriptInset();
+                       if (p && p->has(up)) {
+                               --pos();
+                               push(nextAtom());
+                               idx() = up; // the superscript has index 1
+                               pos() = size();
+                               //lyxerr << "updown: handled by scriptinset to the left" << endl;
+                               return true;
+                       }
                }
-       }
 
-       // try right
-       if (hasNextAtom()) {
-               MathScriptInset const * p = nextAtom()->asScriptInset();
-               if (p && p->has(up)) {
-                       push(nextAtom());
-                       idx() = up;
-                       pos() = 0;
-                       ///lyxerr << "updown: handled by scriptinset to the right" << endl;
-                       return true;
+               // try right
+               if (hasNextAtom()) {
+                       MathScriptInset const * p = nextAtom()->asScriptInset();
+                       if (p && p->has(up)) {
+                               push(nextAtom());
+                               idx() = up;
+                               pos() = 0;
+                               //lyxerr << "updown: handled by scriptinset to the right" << endl;
+                               return true;
+                       }
                }
        }
 
@@ -976,7 +989,7 @@ bool MathCursor::goUpDown(bool up)
 
        // try to find an inset that knows better then we
        while (1) {
-               ///lyxerr << "updown: We are in " << *inset() << " idx: " << idx() << endl;
+               //lyxerr << "updown: We are in " << inset() << " idx: " << idx() << endl;
                // ask inset first
                if (inset()->idxUpDown(idx(), pos(), up, targetx_)) {
                        // try to find best position within this inset
@@ -986,7 +999,7 @@ bool MathCursor::goUpDown(bool up)
                }
 
                // no such inset found, just take something "above"
-               ///lyxerr << "updown: handled by strange case" << endl;
+               //lyxerr << "updown: handled by strange case" << endl;
                if (!popLeft())
                        return
                                bruteFind(xo, yo,
@@ -1235,7 +1248,7 @@ bool MathCursor::interpret(char c)
        }
 
        if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
-               createMathInset(string(1, c));
+               niceInsert(createMathInset(string(1, c)));
                return true;
        }
 
@@ -1400,7 +1413,7 @@ CursorPos MathCursor::normalAnchor() const
 }
 
 
-dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
+DispatchResult MathCursor::dispatch(FuncRequest const & cmd)
 {
        // mouse clicks are somewhat special
        // check
@@ -1410,17 +1423,19 @@ dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
                case LFUN_MOUSE_RELEASE:
                case LFUN_MOUSE_DOUBLE: {
                        CursorPos & pos = Cursor_.back();
-                       dispatch_result res = UNDISPATCHED;
-                       int x = 0, y = 0;
+                       int x = 0;
+                       int y = 0;
                        getPos(x, y);
                        if (x < cmd.x && hasPrevAtom()) {
-                               res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
-                               if (res != UNDISPATCHED)
+                               DispatchResult const res =
+                                       prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
+                               if (res.dispatched())
                                        return res;
                        }
                        if (x > cmd.x && hasNextAtom()) {
-                               res = nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
-                               if (res != UNDISPATCHED)
+                               DispatchResult const res =
+                                       nextAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_);
+                               if (res.dispatched())
                                        return res;
                        }
                }
@@ -1430,16 +1445,17 @@ dispatch_result MathCursor::dispatch(FuncRequest const & cmd)
 
        for (int i = Cursor_.size() - 1; i >= 0; --i) {
                CursorPos & pos = Cursor_[i];
-               dispatch_result res = pos.inset_->dispatch(cmd, pos.idx_, pos.pos_);
-               if (res != UNDISPATCHED) {
-                       if (res == DISPATCHED_POP) {
+               DispatchResult const res =
+                       pos.inset_->dispatch(cmd, pos.idx_, pos.pos_);
+               if (res.dispatched()) {
+                       if (res.val() == FINISHED) {
                                Cursor_.shrink(i + 1);
                                selClear();
                        }
                        return res;
                }
        }
-       return UNDISPATCHED;
+       return DispatchResult(false);
 }