]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
Avoid duplicating mode changing commands
[lyx.git] / src / Cursor.cpp
index baf529bfc84208b2579b6373d1b0a3ba23d33de9..4e63734155a302e6a4b7abc2e8de48de6e0eaf99 100644 (file)
@@ -31,6 +31,7 @@
 #include "Paragraph.h"
 #include "ParIterator.h"
 #include "Row.h"
+#include "texstream.h"
 #include "Text.h"
 #include "TextMetrics.h"
 #include "TocBackend.h"
 
 #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 "support/bind.h"
-
 #include <sstream>
 #include <limits>
 #include <map>
@@ -1184,9 +1185,8 @@ void Cursor::plainInsert(MathAtom const & t)
 
 void Cursor::insert(docstring const & str)
 {
-       for_each(str.begin(), str.end(),
-                bind(static_cast<void(Cursor::*)(char_type)>
-                            (&Cursor::insert), this, _1));
+       for (char_type c : str)
+               insert(c);
 }
 
 
@@ -1449,7 +1449,22 @@ 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
+           && name != from_ascii("ensuremath")) {
+               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
+                  && name != from_ascii("text")) {
+               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) {
@@ -1569,8 +1584,7 @@ void Cursor::normalize()
                        << pos() << ' ' << lastpos() <<  " in idx: " << idx()
                       << " in atom: '";
                odocstringstream os;
-               TexRow texrow(false);
-               otexrowstream ots(os,texrow);
+               otexrowstream ots(os, false);
                WriteStream wi(ots, false, true, WriteStream::wsDefault);
                inset().asInsetMath()->write(wi);
                lyxerr << to_utf8(os.str()) << endl;