* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author André Pönitz
+ * \author André Pönitz
* \author Stefan Schimanski
*
* Full author contact details are available in file CREDITS.
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
-#include "support/assert.h"
+#include "support/lassert.h"
#include <boost/next_prior.hpp>
#include <cstdlib>
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)
{}
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)
+ if (!macroInset || macroInset->name_[0] == '^'
+ || macroInset->name_[0] == '_'
+ || macroInset->name() == edited_name)
continue;
-
+
// get macro
macroInset->updateMacro(mc);
size_t macroNumArgs = 0;
|| 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
}
-void MathData::detachMacroParameters(Cursor * cur, const size_type macroPos)
+void MathData::detachMacroParameters(DocIterator * cur, const size_type macroPos)
{
MathMacro * macroInset = operator[](macroPos).nucleus()->asMacro();
for (size_t q = 0; q < arg.size(); ++q) {
if (arg[q]->getChar() == ']') {
// put brace
- brace = new InsetMathBrace();
+ brace = new InsetMathBrace(buffer_);
break;
}
}
++(*cur)[curMacroSlice - 1].pos();
}
- if (cur) {
- // FIXME: proper anchor handling, this removes the selection
- cur->clearSelection();
+ if (cur)
cur->updateInsets(&cur->bottom().inset());
- }
}
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()
}
// 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;