]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_parser.C
Fix event loop to no longer eat CPU
[lyx.git] / src / mathed / math_parser.C
index 192e642b8fe435d87671ef74c920bcc031a3c890..a050a512cc55c5cccaddb4fdefd1d4c384768359 100644 (file)
@@ -42,6 +42,7 @@ following hack as starting point to write some macros:
 #include "math_arrayinset.h"
 #include "math_braceinset.h"
 #include "math_charinset.h"
+#include "math_colorinset.h"
 #include "math_commentinset.h"
 #include "math_deliminset.h"
 #include "math_envinset.h"
@@ -180,7 +181,11 @@ void delEmptyLastRow(MathGridInset & grid)
                if (!grid.cell(grid.index(row, col)).empty())
                        return;
        }
-       grid.delRow(row + 1);
+       // Copy the row information of the empty row (which would contain the
+       // last hline in the example above) to the dummy row and delete the
+       // empty row.
+       grid.rowinfo(row + 1) = grid.rowinfo(row);
+       grid.delRow(row);
 }
 
 
@@ -934,8 +939,14 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                                              environments_.back() + "}'");
                                else {
                                        environments_.pop_back();
-                                       if (name == "array" ||
-                                           name == "subarray")
+                                       // Delete empty last row in matrix
+                                       // like insets.
+                                       // If you abuse MathGridInset for
+                                       // non-matrix like structures you
+                                       // probably need to refine this test.
+                                       // Right now we only have to test for
+                                       // single line hull insets.
+                                       if (grid.nrows() > 1)
                                                delEmptyLastRow(grid);
                                        return;
                                }
@@ -1048,11 +1059,16 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
 
                else if (t.cs() == "left") {
                        skipSpaces();
-                       string l = getToken().asString();
+                       Token const & tl = getToken();
+                       // \| and \Vert are equivalent, and MathDelimInset
+                       // can't handle \|
+                       // FIXME: fix this in MathDelimInset itself!
+                       string const l = tl.cs() == "|" ? "Vert" : tl.asString();
                        MathArray ar;
                        parse(ar, FLAG_RIGHT, mode);
                        skipSpaces();
-                       string r = getToken().asString();
+                       Token const & tr = getToken();
+                       string const r = tr.cs() == "|" ? "Vert" : tr.asString();
                        cell->push_back(MathAtom(new MathDelimInset(l, r, ar)));
                }
 
@@ -1083,8 +1099,14 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                        }
 
                        else if (name == "split" || name == "cases" ||
-                                        name == "gathered" || name == "aligned" ||
-                                  name == "alignedat") {
+                                name == "gathered" || name == "aligned") {
+                               cell->push_back(createMathInset(name));
+                               parse2(cell->back(), FLAG_END, mode, false);
+                       }
+
+                       else if (name == "alignedat") {
+                               // ignore this for a while
+                               getArg('{', '}');
                                cell->push_back(createMathInset(name));
                                parse2(cell->back(), FLAG_END, mode, false);
                        }
@@ -1181,6 +1203,7 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                }
 
                else if (t.cs() == "label") {
+                       // FIXME: This is swallowed in inline formulas
                        string label = parse_verbatim_item();
                        MathArray ar;
                        asArray(label, ar);
@@ -1202,10 +1225,21 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                }
 
                else if (t.cs() == "color") {
-                       MathAtom at = createMathInset(t.cs());
-                       parse(at.nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
-                       parse(at.nucleus()->cell(1), flags, mode);
-                       cell->push_back(at);
+                       string const color = parse_verbatim_item();
+                       cell->push_back(MathAtom(new MathColorInset(true, color)));
+                       parse(cell->back().nucleus()->cell(0), flags, mode);
+                       return;
+               }
+
+               else if (t.cs() == "textcolor") {
+                       string const color = parse_verbatim_item();
+                       cell->push_back(MathAtom(new MathColorInset(false, color)));
+                       parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
+               }
+
+               else if (t.cs() == "normalcolor") {
+                       cell->push_back(createMathInset(t.cs()));
+                       parse(cell->back().nucleus()->cell(0), flags, mode);
                        return;
                }