From 5ba1dbb45344f6ef1a5f1bdfebffcd23fbea22e9 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Mon, 16 Nov 2009 13:59:23 +0000 Subject: [PATCH] Fix bug #6208: macro crash. The fix consists in not updating the macro while it is being edited, and this is accomplished by the changes in MathData::updateMacros(). However, when clicking away with the mouse I was getting another crash, which is cured by the changes in MathMacro::notifyCursorLeaves(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@32050 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/MathData.cpp | 11 +++++++++-- src/mathed/MathMacro.cpp | 19 ++++++++++--------- status.16x | 3 +++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index f69ae0e840..865e349b4c 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -379,13 +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, + // 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 macroInset->updateMacro(mc); size_t macroNumArgs = 0; diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp index 875bf9cba2..bccdd8004a 100644 --- a/src/mathed/MathMacro.cpp +++ b/src/mathed/MathMacro.cpp @@ -630,15 +630,16 @@ bool MathMacro::notifyCursorLeaves(Cursor const & old, Cursor & cur) 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 inset_cursor = old; + int macroSlice = inset_cursor.find(this); + LASSERT(macroSlice != -1, /**/); + inset_cursor.cutOff(macroSlice); + inset_cursor.recordUndoInset(); + inset_cursor.pop(); + inset_cursor.cell().erase(inset_cursor.pos()); + inset_cursor.cell().insert(inset_cursor.pos(), + createInsetMath(unfolded_name, &cur.buffer())); + cur.updateFlags(cur.disp_.update() | Update::SinglePar); return true; } } diff --git a/status.16x b/status.16x index 86732abca4..bc4df06056 100644 --- a/status.16x +++ b/status.16x @@ -179,6 +179,9 @@ What's new - Fix crash when finishing certain math macros such as \frac or font changing commands (bug 6110). +- Fix crash when undoing changes to an unknown math macro name such that + the macro becomes a known user-defined macro (bug 6208). + - Fix a crash when searching for a string that is found in a table, while the cursor is in math (bug 6112).