mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-31 15:46:16 +00:00
Avoid creating bad math insets with Ctrl+M
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27214 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
fa4801bdc9
commit
28fe97b553
@ -163,13 +163,11 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
|
||||
istringstream is(selstr);
|
||||
Lexer lex;
|
||||
lex.setStream(is);
|
||||
formula->readQuiet(lex);
|
||||
if (formula->getType() == hullNone) {
|
||||
if (!formula->readQuiet(lex)) {
|
||||
// No valid formula, let's try with delims
|
||||
is.str("$" + selstr + "$");
|
||||
lex.setStream(is);
|
||||
formula->readQuiet(lex);
|
||||
if (formula->getType() == hullNone) {
|
||||
if (!formula->readQuiet(lex)) {
|
||||
// Still not valid, leave it as is
|
||||
valid = false;
|
||||
delete formula;
|
||||
|
@ -1585,11 +1585,12 @@ void InsetMathHull::read(Lexer & lex)
|
||||
}
|
||||
|
||||
|
||||
void InsetMathHull::readQuiet(Lexer & lex)
|
||||
bool InsetMathHull::readQuiet(Lexer & lex)
|
||||
{
|
||||
MathAtom at;
|
||||
mathed_parse_normal(at, lex, Parse::QUIET);
|
||||
bool result = mathed_parse_normal(at, lex, Parse::QUIET);
|
||||
operator=(*at->asHullInset());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,7 +113,7 @@ public:
|
||||
///
|
||||
void read(Lexer & lex);
|
||||
///
|
||||
void readQuiet(Lexer & lex);
|
||||
bool readQuiet(Lexer & lex);
|
||||
///
|
||||
int plaintext(odocstream &, OutputParams const &) const;
|
||||
///
|
||||
|
@ -653,10 +653,10 @@ bool Parser::parse(MathAtom & at)
|
||||
// at.nucleus()->cell(0) = ar;
|
||||
//else
|
||||
// lyxerr << "unusual contents found: " << ar << endl;
|
||||
return false;
|
||||
}
|
||||
at = ar[0];
|
||||
return true;
|
||||
success_ = false;
|
||||
} else
|
||||
at = ar[0];
|
||||
return success_;
|
||||
}
|
||||
|
||||
|
||||
@ -1125,11 +1125,19 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
}
|
||||
|
||||
else if (t.cs() == "(") {
|
||||
if (mode == InsetMath::MATH_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
|
||||
parse2(cell->back(), FLAG_SIMPLE2, InsetMath::MATH_MODE, false);
|
||||
}
|
||||
|
||||
else if (t.cs() == "[") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullEquation)));
|
||||
parse2(cell->back(), FLAG_EQUATION, InsetMath::MATH_MODE, false);
|
||||
}
|
||||
@ -1365,32 +1373,56 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
}
|
||||
|
||||
else if (name == "math") {
|
||||
if (mode == InsetMath::MATH_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
|
||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, true);
|
||||
}
|
||||
|
||||
else if (name == "equation" || name == "equation*"
|
||||
|| name == "displaymath") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullEquation)));
|
||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, (name == "equation"));
|
||||
}
|
||||
|
||||
else if (name == "eqnarray" || name == "eqnarray*") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullEqnArray)));
|
||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||
}
|
||||
|
||||
else if (name == "align" || name == "align*") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullAlign)));
|
||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||
}
|
||||
|
||||
else if (name == "flalign" || name == "flalign*") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullFlAlign)));
|
||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||
}
|
||||
|
||||
else if (name == "alignat" || name == "alignat*") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
// ignore this for a while
|
||||
getArg('{', '}');
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullAlignAt)));
|
||||
@ -1398,6 +1430,10 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
}
|
||||
|
||||
else if (name == "xalignat" || name == "xalignat*") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
// ignore this for a while
|
||||
getArg('{', '}');
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullXAlignAt)));
|
||||
@ -1405,6 +1441,10 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
}
|
||||
|
||||
else if (name == "xxalignat") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
// ignore this for a while
|
||||
getArg('{', '}');
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullXXAlignAt)));
|
||||
@ -1412,11 +1452,19 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
}
|
||||
|
||||
else if (name == "multline" || name == "multline*") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullMultline)));
|
||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||
}
|
||||
|
||||
else if (name == "gather" || name == "gather*") {
|
||||
if (mode != InsetMath::UNDECIDED_MODE) {
|
||||
error("bad math environment");
|
||||
break;
|
||||
}
|
||||
cell->push_back(MathAtom(new InsetMathHull(hullGather)));
|
||||
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user