From 0c2902d0c063bed05fe990ddd3e1c963cfd9ebef Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Thu, 9 Jul 2009 15:21:21 +0000 Subject: [PATCH] Better fix for bug #5923. Now the macro name can be freely edited. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30425 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/MathData.cpp | 13 ------------- src/mathed/MathMacro.cpp | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index ac74cca64a..7474632cae 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -386,19 +386,6 @@ void MathData::updateMacros(Cursor * cur, MacroContext const & mc) || macroInset->name_[0] == '_') 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; diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index d5e31f6cdd..44ea1d49dc 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -17,6 +17,7 @@ #include "InsetMathChar.h" #include "MathCompletionList.h" #include "MathExtern.h" +#include "MathFactory.h" #include "MathStream.h" #include "MathSupport.h" @@ -624,6 +625,22 @@ bool MathMacro::idxLast(Cursor & cur) const bool MathMacro::notifyCursorLeaves(Cursor const & old, Cursor & cur) { + if (displayMode_ == DISPLAY_UNFOLDED) { + 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.niceInsert(createInsetMath(unfolded_name)); + if (left) + cur.backwardPos(); + cur.updateFlags(Update::Force); + return true; + } + } cur.updateFlags(Update::Force); return InsetMathNest::notifyCursorLeaves(old, cur); } -- 2.39.2