case LFUN_GREEK:
handleFont(bv, cmd.argument, "lyxgreek1");
if (cmd.argument.size())
- mathcursor->interpret(cmd.argument);
+ mathcursor->insert(asArray(cmd.argument));
break;
case LFUN_MATH_MODE:
#endif
break;
- case LFUN_INSERT_MATRIX:
- if (!cmd.argument.empty()) {
- bv->lockedInsetStoreUndo(Undo::EDIT);
- mathcursor->interpret("matrix " + cmd.argument);
+ case LFUN_INSERT_MATRIX: {
+ bv->lockedInsetStoreUndo(Undo::EDIT);
+ unsigned int m = 1;
+ unsigned int n = 1;
+ string v_align;
+ string h_align;
+ istringstream is(argument);
+ is >> m >> n >> v_align >> h_align;
+ m = max(1u, m);
+ n = max(1u, n);
+ v_align += 'c';
+ mathcursor->niceInsert(
+ MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
updateLocal(bv, true);
- }
break;
+ }
case LFUN_SUPERSCRIPT:
case LFUN_SUBSCRIPT:
argument = "\n";
// fall through
- case -1:
+// FIXME: We probably should swap parts of "math-insert" and "self-insert"
+// handling such that "self-insert" works on "arbitrary stuff" too, and
+// math-insert only handles special math things like "matrix".
case LFUN_INSERT_MATH:
+ bv->lockedInsetStoreUndo(Undo::EDIT);
+ mathcursor->insert(asArray(argument));
+ updateLocal(bv, true);
+ break;
+
+ case -1:
case LFUN_SELFINSERT:
if (!argument.empty()) {
bv->lockedInsetStoreUndo(Undo::EDIT);
if (argument.size() == 1)
result = mathcursor->interpret(argument[0]) ? DISPATCHED : FINISHED_RIGHT;
else
- result = mathcursor->interpret(argument) ? DISPATCHED : FINISHED_RIGHT;
+ mathcursor->insert(asArray(argument));
updateLocal(bv, true);
}
break;
#include "formulabase.h"
#include "funcrequest.h"
#include "math_autocorrect.h"
-#include "math_arrayinset.h"
#include "math_braceinset.h"
#include "math_commentinset.h"
#include "math_charinset.h"
#include "math_extern.h"
#include "math_factory.h"
-#include "math_hullinset.h"
+#include "math_gridinset.h"
#include "math_iterator.h"
#include "math_macroarg.h"
#include "math_macrotemplate.h"
}
}
-/*
- if (prevAtom()->asScriptInset()) {
- // simply enter nucleus
- left();
- return;
- }
-
- if (inNucleus()) {
- // we are in nucleus
- if (pos() == 1) {
- }
- }
-*/
-
--pos();
plainErase();
}
return;
}
-/*
- // if we are standing in front of a script inset, grab item before us and
- // move it into nucleus
- // and remove first thing.
- if (hasNextAtom() && nextAtom()->asScriptInset()) {
- if (hasPrevAtom()) {
- MathAtom at = prevAtom();
- --pos();
- array().erase(pos());
- pushLeft(nextAtom());
- if (array().empty())
- array().push_back(at);
- else
- array()[0] = at;
- pos() = 1;
- } else {
- pushLeft(nextAtom());
- array().clear();
- }
- return;
- }
-*/
-
plainErase();
}
string s = p->name();
--pos();
array().erase(pos());
- if (s != "\\")
- interpret(s);
+
+ // do nothing if the macro name is empty
+ if (s == "\\")
+ return;
+
+ string name = s.substr(1);
+
+ // prevent entering of recursive macros
+ if (formula()->lyxCode() == Inset::MATHMACRO_CODE
+ && formula()->getInsetName() == name)
+ lyxerr << "can't enter recursive macro\n";
+
+ niceInsert(createMathInset(name));
}
}
-bool MathCursor::interpret(string const & s)
-{
- //lyxerr << "interpret 1: '" << s << "'\n";
- if (s.empty())
- return true;
-
- //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
- //owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt);
- //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
-
- if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
- unsigned int m = 1;
- unsigned int n = 1;
- string v_align;
- string h_align;
- istringstream is(s.substr(6).c_str());
- is >> m >> n >> v_align >> h_align;
- m = max(1u, m);
- n = max(1u, n);
- v_align += 'c';
- niceInsert(MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
- return true;
- }
-
- if (s.size() >= 7 && s.substr(0, 7) == "replace") {
- ReplaceData rep;
- istringstream is(s.substr(7).c_str());
- string from, to;
- is >> from >> to;
- mathed_parse_cell(rep.from, from);
- mathed_parse_cell(rep.to, to);
- lyxerr << "replacing '" << from << "' with '" << to << "'\n";
- par()->replace(rep);
- return true;
- }
-
- string name = s.substr(1);
-
- if (name == "over" || name == "choose" || name == "atop") {
- MathAtom t(createMathInset(name));
- t.nucleus()->asNestInset()->cell(0) = array();
- array().clear();
- pos() = 0;
- niceInsert(t);
- popRight();
- left();
- return true;
- }
-
- // prevent entering of recursive macros
- if (formula()->lyxCode() == Inset::MATHMACRO_CODE
- && formula()->getInsetName() == name)
- {
- lyxerr << "can't enter recursive macro\n";
- return true;
- }
-
- niceInsert(createMathInset(name));
- return true;
-}
-
-
bool MathCursor::script(bool up)
{
// Hack to get \\^ and \\_ working
delete mathcursor;
mathcursor = 0;
}
+