]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathData.cpp
Whitespace.
[lyx.git] / src / mathed / MathData.cpp
index ac74cca64a3a36583027e99dcfeb4baf96bc2364..0c41fb634eecd36011ddf50f846ed3ecd4021dfd 100644 (file)
@@ -46,8 +46,8 @@ using namespace std;
 namespace lyx {
 
 
-MathData::MathData(const_iterator from, const_iterator to)
-       : base_type(from, to)
+MathData::MathData(Buffer * buf, const_iterator from, const_iterator to)
+       : base_type(from, to), buffer_(buf)
 {}
 
 
@@ -379,26 +379,20 @@ void MathData::drawT(TextPainter & pain, int x, int y) const
 
 void MathData::updateMacros(Cursor * cur, MacroContext const & mc)
 {
+       // If we are editing a macro, we cannot update it immediately,
+       // otherwise wrong undo steps will be recorded (bug 6208).
+       InsetMath const * inmath = cur ? cur->inset().asInsetMath() : 0;
+       MathMacro const * inmacro = inmath ? inmath->asMacro() : 0;
+       docstring const edited_name = inmacro ? inmacro->name() : docstring();
+
        // go over the array and look for macros
        for (size_t i = 0; i < size(); ++i) {
                MathMacro * macroInset = operator[](i).nucleus()->asMacro();
                if (!macroInset || macroInset->name_[0] == '^'
-                               || macroInset->name_[0] == '_')
+                               || macroInset->name_[0] == '_'
+                               || macroInset->name() == edited_name)
                        continue;
 
-               if (macroInset->displayMode() == MathMacro::DISPLAY_UNFOLDED) {
-                       docstring const & unfolded_name = macroInset->name();
-                       if (unfolded_name != macroInset->name_) {
-                               // macro name was changed
-                               cur->recordUndoInset();
-                               cur->leaveInset(*macroInset);
-                               cur->plainErase();
-                               cur->insert(MathAtom(new InsetMathUnknown('\\'
-                                       + unfolded_name, docstring(), false)));
-                               continue;
-                       }
-               }
-               
                // get macro
                macroInset->updateMacro(mc);
                size_t macroNumArgs = 0;
@@ -421,6 +415,9 @@ void MathData::updateMacros(Cursor * cur, MacroContext const & mc)
                        || newDisplayMode == MathMacro::DISPLAY_UNFOLDED)) {
 
                        detachMacroParameters(cur, i);
+                       // FIXME: proper anchor handling, this removes the selection
+                       if (cur)
+                               cur->clearSelection();
                }
 
                // the macro could have been copied while resizing this
@@ -479,7 +476,7 @@ void MathData::updateMacros(Cursor * cur, MacroContext const & mc)
 }
 
 
-void MathData::detachMacroParameters(Cursor * cur, const size_type macroPos)
+void MathData::detachMacroParameters(DocIterator * cur, const size_type macroPos)
 {
        MathMacro * macroInset = operator[](macroPos).nucleus()->asMacro();
        
@@ -536,7 +533,7 @@ void MathData::detachMacroParameters(Cursor * cur, const size_type macroPos)
                for (size_t q = 0; q < arg.size(); ++q) {
                        if (arg[q]->getChar() == ']') {
                                // put brace
-                               brace = new InsetMathBrace();
+                               brace = new InsetMathBrace(buffer_);
                                break;
                        }
                }
@@ -597,11 +594,8 @@ void MathData::detachMacroParameters(Cursor * cur, const size_type macroPos)
                        ++(*cur)[curMacroSlice - 1].pos();
        }
        
-       if (cur) {
-               // FIXME: proper anchor handling, this removes the selection
-               cur->clearSelection();
+       if (cur)
                cur->updateInsets(&cur->bottom().inset());
-       }
 }
 
 
@@ -685,6 +679,7 @@ void MathData::collectOptionalParameters(Cursor * cur,
        size_t & pos, MathAtom & scriptToPutAround,
        const pos_type macroPos, const int thisPos, const int thisSlice)
 {
+       Buffer * buf = cur ? cur->buffer() : 0;
        // insert optional arguments?
        while (params.size() < numOptionalParams 
               && pos < size()
@@ -722,7 +717,7 @@ void MathData::collectOptionalParameters(Cursor * cur,
                }
                
                // add everything between [ and ] as optional argument
-               MathData optarg(begin() + pos + 1, begin() + right);
+               MathData optarg(buf, begin() + pos + 1, begin() + right);
                
                // a brace?
                bool brace = false;