commit 324651899e605870b410fa9dcad78d4c8dc4fd0f
Author: Enrico Forestieri <[email protected]>
Date: Sat Sep 10 02:07:47 2016 +0200
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.
---
src/Cursor.cpp | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 8d5c63b..6f1a194 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -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,7 +1449,20 @@ bool Cursor::macroModeClose()
else if (atom.nucleus()->nargs() > 0)
atom.nucleus()->cell(0).append(selection);
- plainInsert(atom);
+ 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
if (macroArg) {