]> git.lyx.org Git - features.git/commitdiff
* Support a script also around the ] of an optional parameter
authorStefan Schimanski <sts@lyx.org>
Tue, 22 Jan 2008 17:26:54 +0000 (17:26 +0000)
committerStefan Schimanski <sts@lyx.org>
Tue, 22 Jan 2008 17:26:54 +0000 (17:26 +0000)
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

src/mathed/MathData.cpp
src/mathed/MathData.h

index 114f5b762262d76d64cca989ee951f21ac1e457e..33446a4aa3f86ae576c92d0bf1c95af3852ce791 100644 (file)
@@ -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<MathData> & 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
index c235b2ce18e67d84bc5f29a40ea3e9f55b3fe64b..56da42ca38456831c7f79a9096ff3bb243750c4a 100644 (file)
@@ -181,7 +181,8 @@ private:
        ///
        void collectOptionalParameters(Cursor * cur, 
                const size_type numOptionalParams, std::vector<MathData> & 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<MathData> & params,