Fix bug #7090 (Segfault in refreshing instant preview when math macro changes)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@36873 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2010-12-13 22:25:17 +00:00
parent 0b83e22124
commit 0fa7d11220
2 changed files with 23 additions and 8 deletions

View File

@ -48,6 +48,7 @@
#include "support/docstream.h"
#include "support/lstrings.h"
#include <set>
#include <sstream>
using namespace std;
@ -718,11 +719,11 @@ void MathMacroTemplate::changeArity(Cursor & cur,
{
// remove parameter which do not appear anymore in the definition
for (int i = numargs_; i > newNumArg; --i)
removeParameter(cur, inset_pos, numargs_ - 1, false);
removeParameter(cur, inset_pos, numargs_ - 1, true);
// add missing parameter
for (int i = numargs_; i < newNumArg; ++i)
insertParameter(cur, inset_pos, numargs_, false, false);
insertParameter(cur, inset_pos, numargs_, true, false);
}
@ -788,18 +789,15 @@ void fixMacroInstances(Cursor & cur, DocIterator const & inset_pos,
// remember hull to trigger preview reload
DocIterator hull(dit);
bool preview_reload_needed = false;
set<DocIterator> preview_hulls;
// iterate over all positions until macro is redefined
for (; dit; dit.forwardPos()) {
// left the outer hull?
if (!hull.empty() && dit.depth() == hull.depth()) {
// reload the preview if necessary
// schedule reload of the preview if necessary
if (preview_reload_needed) {
InsetMathHull * inset_hull =
hull.nextInset()->asInsetMath()->asHullInset();
LASSERT(inset_hull, /**/);
inset_hull->reloadPreview(hull, cur.buffer());
cur.updateFlags(Update::Force);
preview_hulls.insert(hull);
preview_reload_needed = false;
}
hull.clear();
@ -835,6 +833,19 @@ void fixMacroInstances(Cursor & cur, DocIterator const & inset_pos,
preview_reload_needed = true;
}
}
if (!preview_hulls.empty()) {
// reload the scheduled previews
set<DocIterator>::const_iterator sit = preview_hulls.begin();
set<DocIterator>::const_iterator end = preview_hulls.end();
for (; sit != end; ++sit) {
InsetMathHull * inset_hull =
sit->nextInset()->asInsetMath()->asHullInset();
LASSERT(inset_hull, /**/);
inset_hull->reloadPreview(*sit, cur.buffer());
}
cur.updateFlags(Update::Force);
}
}
@ -1076,6 +1087,7 @@ bool MathMacroTemplate::getStatus(Cursor & /*cur*/, FuncRequest const & cmd,
flag.setEnabled(numargs_ < 9);
break;
case LFUN_MATH_MACRO_REMOVE_GREEDY_PARAM:
case LFUN_MATH_MACRO_REMOVE_PARAM: {
int num = numargs_;
if (arg.size() != 0)

View File

@ -73,6 +73,9 @@ What's new
- Fix crash when pressing up or down arrow while editing a macro name and
an inline completion is suggested (bug 7068).
- Fix crash when removing a math macro argument while instant preview
is active (bug 7090).
- Fix insertion of a user math macro through the math-insert lfun when a
selection is present (bug 6939).