void MathData::updateMacros(Cursor * cur, MacroContext const & mc)
{
+ // If we are editing a macro, we cannot update it immediately,
+ // as no 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;
// get macro
docstring const & unfolded_name = name();
if (unfolded_name != name_) {
// The macro name was changed
- cur = old;
- bool left = cur.pos() == 0;
- cur.recordUndoInset();
- cur.popForward();
- cur.backspace();
- cur.insert(createInsetMath(unfolded_name, cur.buffer()));
- if (left)
- cur.backwardPos();
- cur.updateFlags(Update::Force);
+ Cursor insetCur = old;
+ int macroSlice = insetCur.find(this);
+ LASSERT(macroSlice != -1, /**/);
+ insetCur.cutOff(macroSlice);
+ insetCur.recordUndoInset();
+ insetCur.pop();
+ insetCur.cell().erase(insetCur.pos());
+ insetCur.cell().insert(insetCur.pos(),
+ createInsetMath(unfolded_name, cur.buffer()));
+ cur.updateFlags(cur.disp_.update() | Update::SinglePar);
return true;
}
}