- increment(it);
- }
-}
-
-
-bool LCursor::idxLineLast()
-{
- idx() -= idx() % ncols();
- idx() += ncols() - 1;
- pos() = lastpos();
- return true;
-}
-
-
-bool LCursor::idxLeft()
-{
- return inset()->idxLeft(*this);
-}
-
-
-bool LCursor::idxRight()
-{
- return inset()->idxRight(*this);
-}
-
-
-bool LCursor::script(bool up)
-{
- // Hack to get \\^ and \\_ working
- lyxerr << "handling script: up: " << up << endl;
- if (inMacroMode() && macroName() == "\\") {
- if (up)
- niceInsert(createMathInset("mathcircumflex"));
- else
- interpret('_');
- return true;
- }
-
- macroModeClose();
- string safe = grabAndEraseSelection();
- if (inNucleus()) {
- // we are in a nucleus of a script inset, move to _our_ script
- inset()->asMathInset()->asScriptInset()->ensure(up);
- idx() = up;
- pos() = 0;
- } else if (pos() != 0 && prevAtom()->asScriptInset()) {
- --pos();
- nextAtom().nucleus()->asScriptInset()->ensure(up);
- push(nextInset());
- idx() = up;
- pos() = lastpos();
- } else if (pos() != 0) {
- --pos();
- cell()[pos()] = MathAtom(new MathScriptInset(nextAtom(), up));
- push(nextInset());
- idx() = up;
- pos() = 0;
- } else {
- plainInsert(MathAtom(new MathScriptInset(up)));
- --pos();
- nextAtom().nucleus()->asScriptInset()->ensure(up);
- push(nextInset());
- idx() = up;
- pos() = 0;
- }
- paste(safe);
- return true;
-}
-
-
-bool LCursor::interpret(char c)
-{
- //lyxerr << "interpret 2: '" << c << "'" << endl;
- clearTargetX();
- if (inMacroArgMode()) {
- posLeft();
- plainErase();
-#warning FIXME
-#if 0
- int n = c - '0';
- MathMacroTemplate const * p = formula()->asMacroTemplate();
- if (p && 1 <= n && n <= p->numargs())
- insert(MathAtom(new MathMacroArgument(c - '0')));
- else {
- insert(createMathInset("#"));
- interpret(c); // try again
- }
-#endif
- return true;
- }
-
- // handle macroMode
- if (inMacroMode()) {
- string name = macroName();
- //lyxerr << "interpret name: '" << name << "'" << endl;
-
- if (isalpha(c)) {
- activeMacro()->setName(activeMacro()->name() + c);
- return true;
- }
-
- // handle 'special char' macros
- if (name == "\\") {
- // remove the '\\'
- backspace();
- if (c == '\\') {
- if (currentMode() == MathInset::TEXT_MODE)
- niceInsert(createMathInset("textbackslash"));
- else
- niceInsert(createMathInset("backslash"));
- } else if (c == '{') {
- niceInsert(MathAtom(new MathBraceInset));
- } else {
- niceInsert(createMathInset(string(1, c)));
- }
- return true;
- }
-
- // leave macro mode and try again if necessary
- macroModeClose();
- if (c == '{')
- niceInsert(MathAtom(new MathBraceInset));
- else if (c != ' ')
- interpret(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;
- }
- }
-
- // just clear selection on pressing the space bar
- if (selection() && c == ' ') {
- selection() = false;
- return true;
- }
-
- selClearOrDel();
-
- if (c == '\\') {
- //lyxerr << "starting with macro" << endl;
- insert(MathAtom(new MathUnknownInset("\\", false)));
- return true;
- }
-
- if (c == '\n') {
- if (currentMode() == MathInset::TEXT_MODE)
- 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 (!pos() != 0 || prevAtom()->getChar() != ' ')
- insert(c);
- return true;
- }
- if (pos() != 0 && prevAtom()->asSpaceInset()) {
- prevAtom().nucleus()->asSpaceInset()->incSpace();
- return true;
- }
- if (popRight())
- return true;
- // if are at the very end, leave the formula
- return pos() != lastpos();
- }
-
- if (c == '_') {
- script(false);
- return true;
- }
-
- if (c == '^') {
- script(true);
- return true;
- }
-
- if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
- niceInsert(createMathInset(string(1, c)));
- return true;
- }
-
- if (c == '%') {
- niceInsert(MathAtom(new MathCommentInset));
- return true;
- }
-
- // try auto-correction
- //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
- // return true;
-
- // no special circumstances, so insert the character without any fuss
- insert(c);
- autocorrect() = true;
- return true;
-}
-
-
-void LCursor::lockToggle()
-{
- if (pos() != lastpos()) {
- // toggle previous inset ...
- nextAtom().nucleus()->lock(!nextAtom()->lock());
- } else if (popLeft() && pos() != lastpos()) {
- // ... or enclosing inset if we are in the last inset position
- nextAtom().nucleus()->lock(!nextAtom()->lock());
- ++pos();