]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathNest.cpp
Fix bug 5802 (http://bugzilla.lyx.org/show_bug.cgi?id=5802)
[lyx.git] / src / mathed / InsetMathNest.cpp
index 11531f661408ca54141cd0fe496536cf1a95dfd9..4f3656a7364e4b6dee7c582fe3cf3f6ec8187d01 100644 (file)
@@ -10,8 +10,6 @@
 
 #include <config.h>
 
-//#define AUTOCORRECT
-
 #include "InsetMathNest.h"
 
 #include "InsetMathArray.h"
@@ -27,9 +25,7 @@
 #include "InsetMathSpace.h"
 #include "InsetMathSymbol.h"
 #include "InsetMathUnknown.h"
-#ifdef AUTOCORRECT
 #include "MathAutoCorrect.h"
-#endif
 #include "MathCompletionList.h"
 #include "MathData.h"
 #include "MathFactory.h"
@@ -633,7 +629,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                }
                // Now that we know exactly what we want to do, let's do it!
                cur.selHandle(select);
-               cur.autocorrect() = false;
                cur.clearTargetX();
                cur.macroModeClose();
                // try moving forward or backwards as necessary...
@@ -985,6 +980,12 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
+       case LFUN_MATH_FONT_STYLE: {
+               FuncRequest fr = FuncRequest(LFUN_MATH_INSERT, '\\' + cmd.argument());
+               doDispatch(cur, fr);
+               break;
+       }
+
        case LFUN_MATH_SIZE: {
                FuncRequest fr = FuncRequest(LFUN_MATH_INSERT, cmd.argument());
                doDispatch(cur, fr);
@@ -1061,8 +1062,11 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                cur.recordUndoSelection();
                if (cmd.argument().empty())
                        cur.insert(MathAtom(new InsetMathSpace));
-               else
-                       cur.insert(MathAtom(new InsetMathSpace(to_utf8(cmd.argument()), "")));
+               else {
+                       string const name = cmd.getArg(0);
+                       string const len = cmd.getArg(1);
+                       cur.insert(MathAtom(new InsetMathSpace(name, len)));
+               }
                break;
 
        case LFUN_ERT_INSERT:
@@ -1255,18 +1259,22 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
                flag.setEnabled(currentMode() != TEXT_MODE);
                break;
 
-       case LFUN_MATH_INSERT: {
+       case LFUN_MATH_FONT_STYLE: {
                bool const textarg =
-                       arg == "\\textbf"   || arg == "\\textsf" ||
-                       arg == "\\textrm"   || arg == "\\textmd" ||
-                       arg == "\\textit"   || arg == "\\textsc" ||
-                       arg == "\\textsl"   || arg == "\\textup" ||
-                       arg == "\\texttt"   || arg == "\\textbb" ||
-                       arg == "\\textnormal";
+                       arg == "textbf"   || arg == "textsf" ||
+                       arg == "textrm"   || arg == "textmd" ||
+                       arg == "textit"   || arg == "textsc" ||
+                       arg == "textsl"   || arg == "textup" ||
+                       arg == "texttt"   || arg == "textbb" ||
+                       arg == "textnormal";
                flag.setEnabled(currentMode() != TEXT_MODE || textarg);
                break;
        }
 
+       case LFUN_MATH_INSERT:
+               flag.setEnabled(currentMode() != TEXT_MODE);
+               break;
+
        case LFUN_MATH_MATRIX:
                flag.setEnabled(currentMode() == MATH_MODE);
                break;
@@ -1517,16 +1525,18 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
                return true;
        }
 
-       // This is annoying as one has to press <space> far too often.
-       // Disable it.
 
-#ifdef AUTOCORRECT
-               // leave autocorrect mode if necessary
-               if (cur.autocorrect() && c == ' ') {
-                       cur.autocorrect() = false;
-                       return true;
-               }
-#endif
+       // leave autocorrect mode if necessary
+       if (lyxrc.autocorrection_math && c == ' ' && cur.autocorrect()) {
+               cur.autocorrect() = false;
+               cur.message(_("Autocorrect Off ('!' to enter)"));
+               return true;
+       } 
+       if (lyxrc.autocorrection_math && c == '!' && !cur.autocorrect()) {
+               cur.autocorrect() = true;
+               cur.message(_("Autocorrect On (<space> to exit)"));
+               return true;
+       }
 
        // just clear selection on pressing the space bar
        if (cur.selection() && c == ' ') {
@@ -1623,15 +1633,19 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c)
        }
 
 
-#ifdef AUTOCORRECT
        // try auto-correction
-       if (cur.autocorrect() && cur.pos() != 0 && math_autocorrect(cur.prevAtom(), c))
+       if (lyxrc.autocorrection_math && cur.autocorrect() && cur.pos() != 0
+                 && math_autocorrect(cur.prevAtom(), c))
                return true;
-#endif
 
        // no special circumstances, so insert the character without any fuss
        cur.insert(c);
-       cur.autocorrect() = true;
+       if (lyxrc.autocorrection_math) {
+               if (!cur.autocorrect())
+                       cur.message(_("Autocorrect Off ('!' to enter)"));
+               else
+                       cur.message(_("Autocorrect On (<space> to exit)"));
+       }
        return true;
 }
 
@@ -1914,6 +1928,7 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
        globals.push_back(from_ascii("\\color"));
        globals.push_back(from_ascii("\\normalcolor"));
        globals.push_back(from_ascii("\\textcolor"));
+       globals.push_back(from_ascii("\\cfrac"));
        globals.push_back(from_ascii("\\dfrac"));
        globals.push_back(from_ascii("\\tfrac"));
        globals.push_back(from_ascii("\\dbinom"));