From: Stefan Schimanski Date: Tue, 22 Jan 2008 17:26:54 +0000 (+0000) Subject: * Support a script also around the ] of an optional parameter X-Git-Tag: 1.6.10~6543 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=daeb335db31fba985c3686626ad95b692c32c339;p=features.git * Support a script also around the ] of an optional parameter Test case: "\newcommand{\foo}[2][a]{(#1,#2)} \foo[A]^1b" should give (a,_)^1b This is implemented for non-optional parameters for long time for cases like \foo ab^2 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22646 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index 114f5b7622..33446a4aa3 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -561,7 +561,7 @@ void MathData::attachMacroParameters(Cursor * cur, // find arguments behind the macro if (!interactiveInit) { collectOptionalParameters(cur, macroOptionals, detachedArgs, p, - macroPos, thisPos, thisSlice); + scriptToPutAround, macroPos, thisPos, thisSlice); collectParameters(cur, macroNumArgs, detachedArgs, p, scriptToPutAround, macroPos, thisPos, thisSlice); } @@ -614,10 +614,13 @@ void MathData::attachMacroParameters(Cursor * cur, void MathData::collectOptionalParameters(Cursor * cur, const size_type numOptionalParams, vector & params, - size_t & pos, const pos_type macroPos, const int thisPos, const int thisSlice) + size_t & pos, MathAtom & scriptToPutAround, + const pos_type macroPos, const int thisPos, const int thisSlice) { // insert optional arguments? - while (params.size() < numOptionalParams && pos < size()) { + while (params.size() < numOptionalParams + && pos < size() + && !scriptToPutAround.nucleus()) { // is a [] block following which could be an optional parameter? if (operator[](pos)->getChar() != '[') break; @@ -625,9 +628,23 @@ void MathData::collectOptionalParameters(Cursor * cur, // found possible optional argument, look for "]" size_t right = pos + 1; for (; right < size(); ++right) { - if (operator[](right)->getChar() == ']') + MathAtom & cell = operator[](right); + + if (cell->getChar() == ']') // found right end break; + + // maybe "]" with a script around? + InsetMathScript * script = cell.nucleus()->asScriptInset(); + if (!script) + continue; + if (script->nuc().size() != 1) + continue; + if (script->nuc()[0]->getChar() == ']') { + // script will be put around the macro later + scriptToPutAround = cell; + break; + } } // found? @@ -676,7 +693,9 @@ void MathData::collectParameters(Cursor * cur, const pos_type macroPos, const int thisPos, const int thisSlice) { // insert normal arguments - for (; params.size() < numParams && pos < size();) { + while (params.size() < numParams + && pos < size() + && !scriptToPutAround.nucleus()) { MathAtom & cell = operator[](pos); // fix cursor diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index c235b2ce18..56da42ca38 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -181,7 +181,8 @@ private: /// void collectOptionalParameters(Cursor * cur, const size_type numOptionalParams, std::vector & params, - size_t & pos, const pos_type macroPos, const int thisPos, const int thisSlice); + size_t & pos, MathAtom & scriptToPutAround, + const pos_type macroPos, const int thisPos, const int thisSlice); /// void collectParameters(Cursor * cur, const size_type numParams, std::vector & params,