mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-27 11:52:25 +00:00
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/trunk@32037 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3581c31d1b
commit
7365a29fea
@ -379,11 +379,18 @@ void MathData::drawT(TextPainter & pain, int x, int y) const
|
|||||||
|
|
||||||
void MathData::updateMacros(Cursor * cur, MacroContext const & mc)
|
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
|
// go over the array and look for macros
|
||||||
for (size_t i = 0; i < size(); ++i) {
|
for (size_t i = 0; i < size(); ++i) {
|
||||||
MathMacro * macroInset = operator[](i).nucleus()->asMacro();
|
MathMacro * macroInset = operator[](i).nucleus()->asMacro();
|
||||||
if (!macroInset || macroInset->name_[0] == '^'
|
if (!macroInset || macroInset->name_[0] == '^'
|
||||||
|| macroInset->name_[0] == '_')
|
|| macroInset->name_[0] == '_'
|
||||||
|
|| macroInset->name() == edited_name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// get macro
|
// get macro
|
||||||
|
@ -633,15 +633,16 @@ bool MathMacro::notifyCursorLeaves(Cursor const & old, Cursor & cur)
|
|||||||
docstring const & unfolded_name = name();
|
docstring const & unfolded_name = name();
|
||||||
if (unfolded_name != name_) {
|
if (unfolded_name != name_) {
|
||||||
// The macro name was changed
|
// The macro name was changed
|
||||||
cur = old;
|
Cursor insetCur = old;
|
||||||
bool left = cur.pos() == 0;
|
int macroSlice = insetCur.find(this);
|
||||||
cur.recordUndoInset();
|
LASSERT(macroSlice != -1, /**/);
|
||||||
cur.popForward();
|
insetCur.cutOff(macroSlice);
|
||||||
cur.backspace();
|
insetCur.recordUndoInset();
|
||||||
cur.insert(createInsetMath(unfolded_name, cur.buffer()));
|
insetCur.pop();
|
||||||
if (left)
|
insetCur.cell().erase(insetCur.pos());
|
||||||
cur.backwardPos();
|
insetCur.cell().insert(insetCur.pos(),
|
||||||
cur.updateFlags(Update::Force);
|
createInsetMath(unfolded_name, cur.buffer()));
|
||||||
|
cur.updateFlags(cur.disp_.update() | Update::SinglePar);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user