]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_nestinset.C
Andreas' patch to prevent crash on click on previewd inset
[lyx.git] / src / mathed / math_nestinset.C
index a14f00a4f6c232bd803c64e105dd6d20449fec33..a71327a84e455bbe11473dd3744f4dc27cc79d51 100644 (file)
@@ -88,7 +88,7 @@ MathArray const & MathNestInset::cell(idx_type i) const
 }
 
 
-void MathNestInset::getCursorPos(CursorSlice const & sl,
+void MathNestInset::cursorPos(CursorSlice const & sl, bool boundary,
        int & x, int & y) const
 {
 // FIXME: This is a hack. Ideally, the coord cache should not store
@@ -458,6 +458,7 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_FINISHED_DOWN:
+               ++cur.pos();
                cur.bv().cursor() = cur;
                break;
 
@@ -473,8 +474,10 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                } else if (cur.posRight() || idxRight(cur)
                        || cur.popRight() || cur.selection())
                        ;
-               else
+               else {
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
+                       cur.undispatched();
+               }
                break;
 
        case LFUN_LEFTSEL:
@@ -490,8 +493,10 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                } else if (cur.posLeft() || idxLeft(cur)
                        || cur.popLeft() || cur.selection())
                        ;
-               else
+               else {
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
+                       cur.undispatched();
+               }
                break;
 
        case LFUN_UPSEL:
@@ -503,8 +508,10 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                        break;
                }
                cur.selHandle(cmd.action == LFUN_UPSEL);
-               if (!cur.up())
+               if (!cur.up()) {
                        cmd = FuncRequest(LFUN_FINISHED_UP);
+                       cur.undispatched();
+               }
                // fixes bug 1598. Please check!
                cur.normalize();
                break;
@@ -516,8 +523,10 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                        break;
                }
                cur.selHandle(cmd.action == LFUN_DOWNSEL);
-               if (!cur.down())
+               if (!cur.down()) {
                        cmd = FuncRequest(LFUN_FINISHED_DOWN);
+                       cur.undispatched();
+               }
                // fixes bug 1598. Please check!
                cur.normalize();
                break;
@@ -611,13 +620,16 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                recordUndo(cur);
                cur.erase();
                cmd = FuncRequest(LFUN_FINISHED_LEFT);
+               cur.undispatched();
                break;
 
        case LFUN_ESCAPE:
                if (cur.selection())
                        cur.clearSelection();
-               else
+               else  {
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
+                       cur.undispatched();
+               }
                break;
 
        case LFUN_INSET_TOGGLE:
@@ -639,8 +651,10 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                        cur.insert(cmd.argument);
                        break;
                }
-               if (!interpret(cur, cmd.argument[0]))
+               if (!interpret(cur, cmd.argument[0])) {
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
+                       cur.undispatched();
+               }
                break;
 
        //case LFUN_GETXY:
@@ -715,7 +729,10 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
                        handleFont(cur, cmd.argument, "mathrm");
                break;
        case LFUN_CODE:
+               if (currentMode() == TEXT_MODE)
                        handleFont(cur, cmd.argument, "texttt");
+               else
+                       handleFont(cur, cmd.argument, "mathtt");
                break;
        case LFUN_FRAK:
                handleFont(cur, cmd.argument, "mathfrak");
@@ -910,28 +927,18 @@ bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd,
                }
                flag.setOnOff(cmd.argument[0] == align);
                break;
+#endif
+       /// We have to handle them since 1.4 blocks all unhandled actions
+       case LFUN_ITAL:
        case LFUN_BOLD:
-               flag.setOnOff(tc == "mathbf");
-               break;
        case LFUN_SANS:
-               flag.setOnOff(tc == "mathsf");
-               break;
        case LFUN_EMPH:
-               flag.setOnOff(tc == "mathcal");
-               break;
-       case LFUN_ROMAN:
-               flag.setOnOff(tc == "mathrm");
-               break;
        case LFUN_CODE:
-               flag.setOnOff(tc == "mathtt");
-               break;
        case LFUN_NOUN:
-               flag.setOnOff(tc == "mathbb");
-               break;
+       case LFUN_ROMAN:
        case LFUN_DEFAULT:
-               flag.setOnOff(tc == "mathnormal");
+               flag.enabled(true);
                break;
-#endif
        case LFUN_MATH_MUTATE:
                //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
                flag.setOnOff(false);
@@ -980,33 +987,33 @@ void MathNestInset::edit(LCursor & cur, bool left)
        cur.idx() = left ? 0 : cur.lastidx();
        cur.pos() = left ? 0 : cur.lastpos();
        cur.resetAnchor();
-       lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
+       //lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
 }
 
 
-InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y) const
+InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y)
 {
        int idx_min = 0;
        int dist_min = 1000000;
-       for (idx_type i = 0; i < nargs(); ++i) {
-               int d = cell(i).dist(x, y);
+       for (idx_type i = 0, n = nargs(); i != n; ++i) {
+               int const d = cell(i).dist(x, y);
                if (d < dist_min) {
                        dist_min = d;
                        idx_min = i;
                }
        }
-       MathArray const & ar = cell(idx_min);
-       cur.push(const_cast<MathNestInset&>(*this));
+       MathArray & ar = cell(idx_min);
+       cur.push(*this);
        cur.idx() = idx_min;
        cur.pos() = ar.x2pos(x - ar.xo());
-       lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
+       //lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
        if (dist_min == 0) {
                // hit inside cell
                for (pos_type i = 0, n = ar.size(); i < n; ++i)
                        if (ar[i]->covers(x, y))
                                return ar[i].nucleus()->editXY(cur, x, y);
        }
-       return const_cast<MathNestInset*>(this);
+       return this;
 }
 
 
@@ -1074,7 +1081,7 @@ void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
 
 bool MathNestInset::interpret(LCursor & cur, char c)
 {
-       lyxerr << "interpret 2: '" << c << "'" << endl;
+       //lyxerr << "interpret 2: '" << c << "'" << endl;
        cur.clearTargetX();
 
        // handle macroMode
@@ -1186,7 +1193,6 @@ bool MathNestInset::interpret(LCursor & cur, char c)
                        script(cur, false);
                        return true;
                }
-
                if (c == '^') {
                        script(cur, true);
                        return true;
@@ -1197,7 +1203,8 @@ bool MathNestInset::interpret(LCursor & cur, char c)
                }
        }
 
-       if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%') {
+       if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%'
+      || c == '_' || c == '^') {
                cur.niceInsert(createMathInset(string(1, c)));
                return true;
        }
@@ -1245,10 +1252,10 @@ bool MathNestInset::script(LCursor & cur, bool up)
                // convert the thing to our left to a scriptinset or create a new
                // one if in the very first position of the array
                if (cur.pos() == 0) {
-                       lyxerr << "new scriptinset" << endl;
+                       //lyxerr << "new scriptinset" << endl;
                        cur.insert(new MathScriptInset(up));
                } else {
-                       lyxerr << "converting prev atom " << endl;
+                       //lyxerr << "converting prev atom " << endl;
                        cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up));
                }
                --cur.pos();
@@ -1257,9 +1264,9 @@ bool MathNestInset::script(LCursor & cur, bool up)
                cur.idx() = 1;
                cur.pos() = 0;
        }
-       lyxerr << "pasting 1: safe:\n" << safe << endl;
+       //lyxerr << "pasting 1: safe:\n" << safe << endl;
        cur.paste(safe);
        cur.resetAnchor();
-       lyxerr << "pasting 2: safe:\n" << safe << endl;
+       //lyxerr << "pasting 2: safe:\n" << safe << endl;
        return true;
 }