mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Smash remaining drawbacks for bug 2315
http://bugzilla.lyx.org/show_bug.cgi?id=2315 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26792 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c5ec5460d7
commit
f505227f6e
@ -67,6 +67,7 @@
|
||||
|
||||
#include "mathed/InsetMathHull.h"
|
||||
#include "mathed/MathMacroTemplate.h"
|
||||
#include "mathed/MathParser.h"
|
||||
|
||||
#include <boost/next_prior.hpp>
|
||||
|
||||
@ -127,6 +128,9 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
|
||||
// It may happen that sel is empty but there is a selection
|
||||
replaceSelection(cur);
|
||||
|
||||
// Is this a valid formula?
|
||||
bool valid = true;
|
||||
|
||||
if (sel.empty()) {
|
||||
#ifdef ENABLE_ASSERTIONS
|
||||
const int old_pos = cur.pos();
|
||||
@ -156,20 +160,35 @@ static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
|
||||
&& sel.find(from_ascii("\\def")) == string::npos)
|
||||
{
|
||||
InsetMathHull * formula = new InsetMathHull;
|
||||
istringstream is(to_utf8(sel));
|
||||
string const selstr = to_utf8(sel);
|
||||
istringstream is(selstr);
|
||||
Lexer lex;
|
||||
lex.setStream(is);
|
||||
mathed_parser_warn_contents(false);
|
||||
formula->read(lex);
|
||||
if (formula->getType() == hullNone)
|
||||
// Don't create pseudo formulas if
|
||||
// delimiters are left out
|
||||
formula->mutate(hullSimple);
|
||||
cur.insert(formula);
|
||||
if (formula->getType() == hullNone) {
|
||||
// No valid formula, let's try with delims
|
||||
is.str("$" + selstr + "$");
|
||||
lex.setStream(is);
|
||||
formula->read(lex);
|
||||
if (formula->getType() == hullNone) {
|
||||
// Still not valid, leave it as is
|
||||
valid = false;
|
||||
delete formula;
|
||||
cur.insert(sel);
|
||||
} else
|
||||
cur.insert(formula);
|
||||
} else
|
||||
cur.insert(formula);
|
||||
mathed_parser_warn_contents(true);
|
||||
} else {
|
||||
cur.insert(new MathMacroTemplate(sel));
|
||||
}
|
||||
}
|
||||
cur.message(from_utf8(N_("Math editor mode")));
|
||||
if (valid)
|
||||
cur.message(from_utf8(N_("Math editor mode")));
|
||||
else
|
||||
cur.message(from_utf8(N_("No valid math formula")));
|
||||
}
|
||||
|
||||
|
||||
|
@ -79,6 +79,9 @@ namespace lyx {
|
||||
|
||||
namespace {
|
||||
|
||||
bool warn_unusual_contents = true;
|
||||
|
||||
|
||||
InsetMath::mode_type asMode(InsetMath::mode_type oldmode, docstring const & str)
|
||||
{
|
||||
//lyxerr << "handling mode: '" << str << "'" << endl;
|
||||
@ -611,7 +614,8 @@ bool Parser::parse(MathAtom & at)
|
||||
MathData ar;
|
||||
parse(ar, false, InsetMath::UNDECIDED_MODE);
|
||||
if (ar.size() != 1 || ar.front()->getType() == hullNone) {
|
||||
lyxerr << "unusual contents found: " << ar << endl;
|
||||
if (warn_unusual_contents)
|
||||
lyxerr << "unusual contents found: " << ar << endl;
|
||||
at = MathAtom(new InsetMathPar(ar));
|
||||
//if (at->nargs() > 0)
|
||||
// at.nucleus()->cell(0) = ar;
|
||||
@ -1687,6 +1691,12 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
} // anonymous namespace
|
||||
|
||||
|
||||
void mathed_parser_warn_contents(bool warn)
|
||||
{
|
||||
warn_unusual_contents = warn;
|
||||
}
|
||||
|
||||
|
||||
void mathed_parse_cell(MathData & ar, docstring const & str)
|
||||
{
|
||||
Parser(str).parse(ar, 0, InsetMath::MATH_MODE);
|
||||
|
@ -58,6 +58,9 @@ public:
|
||||
/// check whether this is a well-known (La)TeX macro or primitive
|
||||
latexkeys const * in_word_set(docstring const & str);
|
||||
|
||||
/// tell the parser whether it should warn about unusual contents
|
||||
void mathed_parser_warn_contents(bool);
|
||||
|
||||
/// parse formula from a string
|
||||
bool mathed_parse_normal(MathAtom &, docstring const &);
|
||||
/// ... the LyX lexxer
|
||||
|
Loading…
Reference in New Issue
Block a user