- if (!editing(pi.base.bv))
- return;
- int t = x + dim_.width() - 1;
- int d = y + dim_.descent();
- pi.pain.line(x, d - 3, x, d, LColor::mathframe);
- pi.pain.line(t, d - 3, t, d, LColor::mathframe);
- pi.pain.line(x, d, x + 3, d, LColor::mathframe);
- pi.pain.line(t - 3, d, t, d, LColor::mathframe);
+ lyxerr << "interpret 2: '" << c << "'" << endl;
+ cur.clearTargetX();
+
+ // handle macroMode
+ if (cur.inMacroMode()) {
+ string name = cur.macroName();
+
+ /// are we currently typing '#1' or '#2' or...?
+ if (name == "\\#") {
+ cur.backspace();
+ int n = c - '0';
+ if (n >= 1 && n <= 9)
+ cur.insert(new MathMacroArgument(n));
+ return true;
+ }
+
+ if (isalpha(c)) {
+ cur.activeMacro()->setName(name + c);
+ return true;
+ }
+
+ // handle 'special char' macros
+ if (name == "\\") {
+ // remove the '\\'
+ if (c == '\\') {
+ cur.backspace();
+ if (currentMode() == MathInset::TEXT_MODE)
+ cur.niceInsert(createMathInset("textbackslash"));
+ else
+ cur.niceInsert(createMathInset("backslash"));
+ } else if (c == '{') {
+ cur.backspace();
+ cur.niceInsert(MathAtom(new MathBraceInset));
+ } else if (c == '%') {
+ cur.backspace();
+ cur.niceInsert(MathAtom(new MathCommentInset));
+ } else if (c == '#') {
+ BOOST_ASSERT(cur.activeMacro());
+ cur.activeMacro()->setName(name + c);
+ } else {
+ cur.backspace();
+ cur.niceInsert(createMathInset(string(1, c)));
+ }
+ return true;
+ }
+
+ // leave macro mode and try again if necessary
+ cur.macroModeClose();
+ if (c == '{')
+ cur.niceInsert(MathAtom(new MathBraceInset));
+ else if (c != ' ')
+ interpret(cur, c);
+ return true;
+ }
+
+ // This is annoying as one has to press <space> far too often.
+ // Disable it.
+
+#if 0
+ // leave autocorrect mode if necessary
+ if (autocorrect() && c == ' ') {
+ autocorrect() = false;
+ return true;
+ }
+#endif
+
+ // just clear selection on pressing the space bar
+ if (cur.selection() && c == ' ') {
+ cur.selection() = false;
+ return true;
+ }
+
+ selClearOrDel(cur);
+
+ if (c == '\\') {
+ //lyxerr << "starting with macro" << endl;
+ cur.insert(MathAtom(new MathUnknownInset("\\", false)));
+ return true;
+ }
+
+ if (c == '\n') {
+ if (currentMode() == MathInset::TEXT_MODE)
+ cur.insert(c);
+ return true;
+ }
+
+ if (c == ' ') {
+ if (currentMode() == MathInset::TEXT_MODE) {
+ // insert spaces in text mode,
+ // but suppress direct insertion of two spaces in a row
+ // the still allows typing '<space>a<space>' and deleting the 'a', but
+ // it is better than nothing...
+ if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
+ cur.insert(c);
+ return true;
+ }
+ if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
+ cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
+ return true;
+ }
+ if (cur.popRight())
+ return true;
+ // if are at the very end, leave the formula
+ return cur.pos() != cur.lastpos();
+ }
+
+ if (c == '_') {
+ script(cur, false);
+ return true;
+ }
+
+ if (c == '^') {
+ script(cur, true);
+ return true;
+ }
+
+ if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%') {
+ cur.niceInsert(createMathInset(string(1, c)));
+ return true;
+ }
+
+ if (c == '~') {
+ cur.niceInsert(createMathInset("sim"));
+ return true;
+ }
+
+ // try auto-correction
+ //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
+ // return true;
+
+ // no special circumstances, so insert the character without any fuss
+ cur.insert(c);
+ cur.autocorrect() = true;
+ return true;