Ensure proper mode in mathed

A math-mode command entered in a text-mode environment is wrapped
in an ensuremath inset, as well as a text-mode command entered in a
math-mode environment is wrapped in a text inset. Who doesn't like
the extra insets can always dissolve them and rely on the wrapping
performed on export.
This commit is contained in:
Enrico Forestieri 2016-09-10 02:07:47 +02:00
parent b9a47dff4e
commit 324651899e

View File

@ -47,9 +47,11 @@
#include "mathed/InsetMath.h"
#include "mathed/InsetMathBrace.h"
#include "mathed/InsetMathEnsureMath.h"
#include "mathed/InsetMathScript.h"
#include "mathed/MacroTable.h"
#include "mathed/MathData.h"
#include "mathed/MathFactory.h"
#include "mathed/MathMacro.h"
#include <sstream>
@ -1447,6 +1449,19 @@ bool Cursor::macroModeClose()
else if (atom.nucleus()->nargs() > 0)
atom.nucleus()->cell(0).append(selection);
if (in->currentMode() == Inset::TEXT_MODE
&& atom.nucleus()->currentMode() == Inset::MATH_MODE) {
MathAtom at(new InsetMathEnsureMath(buffer()));
at.nucleus()->cell(0).push_back(atom);
niceInsert(at);
posForward();
} else if (in->currentMode() == Inset::MATH_MODE
&& atom.nucleus()->currentMode() == Inset::TEXT_MODE) {
MathAtom at = createInsetMath("text", buffer());
at.nucleus()->cell(0).push_back(atom);
niceInsert(at);
posForward();
} else
plainInsert(atom);
// finally put the macro argument behind, if needed