]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_nestinset.C
Make Helge happy: no more crash on arrow up/down in math macro
[lyx.git] / src / mathed / math_nestinset.C
index 9c992cfaee74d657584b9e68dd3e6f56bded7c30..79ca87f7799b544ca00724d277bca077742ad453 100644 (file)
@@ -13,6 +13,7 @@
 #include "math_nestinset.h"
 
 #include "math_arrayinset.h"
+#include "math_boxinset.h"
 #include "math_braceinset.h"
 #include "math_commentinset.h"
 #include "math_data.h"
@@ -21,7 +22,7 @@
 #include "math_hullinset.h"
 #include "math_mathmlstream.h"
 #include "math_macroarg.h"
-#include "math_mboxinset.h"
+//#include "math_mboxinset.h"
 #include "math_parser.h"
 #include "math_scriptinset.h"
 #include "math_spaceinset.h"
@@ -63,18 +64,6 @@ using std::string;
 using std::istringstream;
 
 
-
-namespace {
-
-// local global
-int first_x;
-int first_y;
-
-} // namespace anon
-
-
-
-
 MathNestInset::MathNestInset(idx_type nargs)
        : cells_(nargs), lock_(false)
 {}
@@ -139,6 +128,7 @@ void MathNestInset::getCursorPos(CursorSlice const & sl,
                x += 2;
 }
 
+
 void MathNestInset::metrics(MetricsInfo const & mi) const
 {
        MetricsInfo m = mi;
@@ -506,6 +496,12 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_UPSEL:
        case LFUN_UP:
+               // FIXME Tried to use clearTargetX and macroModeClose, crashed on cur.up()
+               if (cur.inMacroMode()) {
+                       // Make Helge happy
+                       cur.macroModeClose();
+                       break;
+               }
                cur.selHandle(cmd.action == LFUN_UPSEL);
                if (!cur.up())
                        cmd = FuncRequest(LFUN_FINISHED_UP);
@@ -515,6 +511,10 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_DOWNSEL:
        case LFUN_DOWN:
+               if (cur.inMacroMode()) {
+                       cur.macroModeClose();
+                       break;
+               }
                cur.selHandle(cmd.action == LFUN_DOWNSEL);
                if (!cur.down())
                        cmd = FuncRequest(LFUN_FINISHED_DOWN);
@@ -567,7 +567,7 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                cur.clearTargetX();
                if (cur.pos() != cur.lastpos()) {
                        cur.pos() = cur.lastpos();
-               } else if (cur.col() != cur.lastcol()) {
+               } else if (ncols() && (cur.col() != cur.lastcol())) {
                        cur.idx() = cur.idx() - cur.col() + cur.lastcol();
                        cur.pos() = cur.lastpos();
                } else if (cur.idx() != cur.lastidx()) {
@@ -724,7 +724,8 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                        break;
                cur.macroModeClose();
                selClearOrDel(cur);
-               cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
+               //cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
+               cur.plainInsert(MathAtom(new MathBoxInset("mbox")));
                cur.posLeft();
                cur.pushLeft(*cur.nextInset());
 #else
@@ -804,10 +805,16 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
 // handling such that "self-insert" works on "arbitrary stuff" too, and
 // math-insert only handles special math things like "matrix".
-       case LFUN_INSERT_MATH:
+       case LFUN_INSERT_MATH: {
                recordUndo(cur, Undo::ATOMIC);
-               cur.niceInsert(cmd.argument);
+               MathArray ar;
+               asArray(cmd.argument, ar);
+               if (ar.size() == 1 && (ar[0].nucleus()->asNestInset())) {
+                       cur.handleNest(ar[0]);
+               } else
+                       cur.niceInsert(cmd.argument);
                break;
+               }
 
        case LFUN_DIALOG_SHOW_NEW_INSET: {
                string const & name = cmd.argument;
@@ -956,11 +963,9 @@ InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y) const
 
 void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
 {
-       lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
+       //lyxerr << "## lfunMousePress: buttons: " << cmd.button() << endl;
        if (cmd.button() == mouse_button::button1) {
-               first_x = cmd.x;
-               first_y = cmd.y;
-               lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
+               //lyxerr << "## lfunMousePress: setting cursor to: " << cur << endl;
                cur.resetAnchor();
                cur.bv().cursor() = cur;
        }
@@ -976,22 +981,22 @@ void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
        // only select with button 1
        if (cmd.button() == mouse_button::button1) {
                LCursor & bvcur = cur.bv().cursor();
-               if (abs(cmd.x - first_x) + abs(cmd.y - first_y) > 4
-                   && bvcur.anchor_.hasPart(cur)) {
-                       first_x = cmd.x;
-                       first_y = cmd.y;
-
+               if (bvcur.anchor_.hasPart(cur)) {
+                       //lyxerr << "## lfunMouseMotion: cursor: " << cur << endl;
                        bvcur.setCursor(cur);
                        bvcur.selection() = true;
-               } else
+                       //lyxerr << "MOTION " << bvcur << endl;
+               }
+               else {
                        cur.undispatched();
+               }
        }
 }
 
 
 void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
 {
-       lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
+       //lyxerr << "## lfunMouseRelease: buttons: " << cmd.button() << endl;
 
        if (cmd.button() == mouse_button::button1) {
                //cur.bv().stuffClipboard(cur.grabSelection());