Fix bug #6739: Loading in a 1.6.5 file causes 1.6.6-1 to crash

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@34580 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2010-06-01 13:34:31 +00:00
parent a71bf0ec16
commit cb3044101e
2 changed files with 21 additions and 11 deletions

View File

@ -614,7 +614,7 @@ void MathData::attachMacroParameters(Cursor * cur,
size_t p = macroPos + 1; size_t p = macroPos + 1;
vector<MathData> detachedArgs; vector<MathData> detachedArgs;
MathAtom scriptToPutAround; MathAtom scriptToPutAround;
// find cursor slice again of this MathData // find cursor slice again of this MathData
int thisSlice = -1; int thisSlice = -1;
if (cur) if (cur)
@ -622,7 +622,7 @@ void MathData::attachMacroParameters(Cursor * cur,
int thisPos = -1; int thisPos = -1;
if (thisSlice != -1) if (thisSlice != -1)
thisPos = (*cur)[thisSlice].pos(); thisPos = (*cur)[thisSlice].pos();
// find arguments behind the macro // find arguments behind the macro
if (!interactiveInit) { if (!interactiveInit) {
collectOptionalParameters(cur, macroOptionals, detachedArgs, p, collectOptionalParameters(cur, macroOptionals, detachedArgs, p,
@ -630,27 +630,34 @@ void MathData::attachMacroParameters(Cursor * cur,
} }
collectParameters(cur, macroNumArgs, detachedArgs, p, collectParameters(cur, macroNumArgs, detachedArgs, p,
scriptToPutAround, macroPos, thisPos, thisSlice, appetite); scriptToPutAround, macroPos, thisPos, thisSlice, appetite);
// attach arguments back to macro inset // attach arguments back to macro inset
macroInset->attachArguments(detachedArgs, macroNumArgs, macroOptionals); macroInset->attachArguments(detachedArgs, macroNumArgs, macroOptionals);
// found tail script? E.g. \foo{a}b^x // found tail script? E.g. \foo{a}b^x
if (scriptToPutAround.nucleus()) { if (scriptToPutAround.nucleus()) {
InsetMathScript * scriptInset =
scriptToPutAround.nucleus()->asScriptInset();
// In the math parser we remove empty braces in the base
// of a script inset, but we have to restore them here.
if (scriptInset->nuc().empty()) {
MathData ar;
scriptInset->nuc().push_back(
MathAtom(new InsetMathBrace(ar)));
}
// put macro into a script inset // put macro into a script inset
scriptToPutAround.nucleus()->asScriptInset()->nuc()[0] scriptInset->nuc()[0] = operator[](macroPos);
= operator[](macroPos);
operator[](macroPos) = scriptToPutAround; operator[](macroPos) = scriptToPutAround;
// go into the script inset nucleus // go into the script inset nucleus
if (cur && thisPos == int(macroPos)) if (cur && thisPos == int(macroPos))
cur->append(0, 0); cur->append(0, 0);
// get pointer to "deep" copied macro inset // get pointer to "deep" copied macro inset
InsetMathScript * scriptInset scriptInset = operator[](macroPos).nucleus()->asScriptInset();
= operator[](macroPos).nucleus()->asScriptInset();
macroInset = scriptInset->nuc()[0].nucleus()->asMacro(); macroInset = scriptInset->nuc()[0].nucleus()->asMacro();
} }
// remove them from the MathData // remove them from the MathData
erase(begin() + macroPos + 1, begin() + p); erase(begin() + macroPos + 1, begin() + p);
@ -661,7 +668,7 @@ void MathData::attachMacroParameters(Cursor * cur,
// fix cursor if right of p // fix cursor if right of p
if (thisPos >= int(p)) if (thisPos >= int(p))
(*cur)[thisSlice].pos() -= p - (macroPos + 1); (*cur)[thisSlice].pos() -= p - (macroPos + 1);
// was the macro inset just inserted interactively and was now folded // was the macro inset just inserted interactively and was now folded
// and the cursor is just behind? // and the cursor is just behind?
if ((*cur)[thisSlice].pos() == int(macroPos + 1) if ((*cur)[thisSlice].pos() == int(macroPos + 1)

View File

@ -92,6 +92,9 @@ What's new
- Allow to overwrite files without dialog popup on export from GUI - Allow to overwrite files without dialog popup on export from GUI
(bug 2844). (bug 2844).
- Fix assertion when using an empty user macro taking an argument as
the base of script inset (bug 6739).
* USER INTERFACE * USER INTERFACE