#include "InsetMathBig.h"
#include "InsetMathBox.h"
#include "InsetMathBrace.h"
+#include "InsetMathChar.h"
#include "InsetMathColor.h"
#include "InsetMathComment.h"
#include "InsetMathDelim.h"
+#include "InsetMathEnsureMath.h"
#include "InsetMathHull.h"
#include "InsetMathRef.h"
#include "InsetMathScript.h"
#include "Cursor.h"
#include "CutAndPaste.h"
#include "DispatchResult.h"
+#include "Encoding.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LyXFunc.h"
{
//lyxerr << "InsetMathNest: request: " << cmd << endl;
- Parse::flags parseflg = Parse::QUIET;
+ Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
switch (cmd.action) {
// InsetMathFrac -> a pos value > 0 is invalid.
// A side effect is that an undo before the macro is finished
// undoes the complete macro, not only the last character.
- if (!cur.inMacroMode())
- cur.recordUndoSelection();
+ if (!cur.inMacroMode()) {
+ MathMacro const * macro = 0;
+ if (cur.pos() > 0 && cmd.argument() != "\\")
+ macro = cur.inset().asInsetMath()->asMacro();
+
+ if (!macro)
+ cur.recordUndoSelection();
+ }
// spacial handling of space. If we insert an inset
// via macro mode, we want to put the cursor inside it
docstring const save_selection = grabAndEraseSelection(cur);
selClearOrDel(cur);
//cur.plainInsert(MathAtom(new InsetMathMBox(cur.bv())));
- cur.plainInsert(MathAtom(new InsetMathBox(from_ascii("mbox"))));
+ if (currentMode() == Inset::TEXT_MODE)
+ cur.plainInsert(MathAtom(new InsetMathEnsureMath));
+ else
+ cur.plainInsert(MathAtom(new InsetMathBox(from_ascii("mbox"))));
cur.posBackward();
cur.pushBackward(*cur.nextInset());
cur.niceInsert(save_selection);
case LFUN_FONT_DEFAULT:
flag.setEnabled(true);
break;
- case LFUN_MATH_MUTATE:
- //flag.setOnOff(mathcursor::formula()->hullType() == to_utf8(cmd.argument()));
- flag.setOnOff(false);
- break;
// we just need to be in math mode to enable that
case LFUN_MATH_SIZE:
}
// leave macro mode and try again if necessary
- cur.macroModeClose();
+ if (cur.macroModeClose()) {
+ MathAtom const atom = cur.prevAtom();
+ if (atom->asNestInset() && atom->isActive()) {
+ cur.posBackward();
+ cur.pushBackward(*cur.nextInset());
+ }
+ }
if (c == '{')
cur.niceInsert(MathAtom(new InsetMathBrace));
else if (c != ' ')
return true;
}
+ if (cur.pos() > 0) {
+ MathMacro const * macro = cur.inset().asInsetMath()->asMacro();
+ if (macro) {
+ // resume macro_mode
+ docstring const & s = macro->name();
+ cur.leaveInset(*macro);
+ cur.plainErase();
+ docstring safe = grabAndEraseSelection(cur);
+ cur.insert(MathAtom(new InsetMathUnknown("\\" + s + c, safe, false)));
+ return true;
+ }
+ }
+
selClearOrDel(cur);
if (c == '\n') {
cur.niceInsert(createInsetMath("sim"));
return true;
}
+ if (!isAsciiOrMathAlpha(c)) {
+ MathAtom at = createInsetMath("text");
+ at.nucleus()->cell(0).push_back(MathAtom(new InsetMathChar(c)));
+ cur.niceInsert(at);
+ cur.posForward();
+ return true;
+ }
} else {
if (c == '^') {
cur.niceInsert(createInsetMath("textasciicircum"));
globals.push_back(from_ascii("\\normalcolor"));
globals.push_back(from_ascii("\\textcolor"));
globals.push_back(from_ascii("\\cfrac"));
+ globals.push_back(from_ascii("\\cfracleft"));
+ globals.push_back(from_ascii("\\cfracright"));
globals.push_back(from_ascii("\\dfrac"));
globals.push_back(from_ascii("\\tfrac"));
globals.push_back(from_ascii("\\dbinom"));