]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_cursor.C
updates to latexfeatures stuff; allow empty \document_path
[lyx.git] / src / mathed / math_cursor.C
index efd13f33b7bb07029b1fc504f2220b124aaf87b6..e54922cae0898837ea7d06d86854bba7785278ca 100644 (file)
@@ -168,7 +168,7 @@ Selection theSelection;
 
 
 MathCursor::MathCursor(InsetFormulaBase * formula, bool left)
-       : formula_(formula), lastcode_(LM_TC_VAR), selection_(false)
+       : formula_(formula), lastcode_(LM_TC_MIN), selection_(false)
 {
        left ? first() : last();
 }
@@ -300,11 +300,11 @@ bool MathCursor::left(bool sel)
        dump("Left 1");
        if (inMacroMode()) {
                macroModeClose();
-               lastcode_ = LM_TC_VAR;
+               lastcode_ = LM_TC_MIN;
                return true;
        }
        selHandle(sel);
-       lastcode_ = LM_TC_VAR;
+       lastcode_ = LM_TC_MIN;
 
        if (hasPrevAtom() && openable(prevAtom(), sel)) {
                if (prevAtom()->isHyperActive()) {
@@ -323,11 +323,11 @@ bool MathCursor::right(bool sel)
        dump("Right 1");
        if (inMacroMode()) {
                macroModeClose();
-               lastcode_ = LM_TC_VAR;
+               lastcode_ = LM_TC_MIN;
                return true;
        }
        selHandle(sel);
-       lastcode_ = LM_TC_VAR;
+       lastcode_ = LM_TC_MIN;
 
        if (hasNextAtom() && openable(nextAtom(), sel)) {
                if (nextAtom()->isHyperActive()) {
@@ -396,7 +396,7 @@ void MathCursor::home(bool sel)
        dump("home 1");
        selHandle(sel);
        macroModeClose();
-       lastcode_ = LM_TC_VAR;
+       lastcode_ = LM_TC_MIN;
        if (!par()->idxHome(idx(), pos())) 
                popLeft();
        dump("home 2");
@@ -408,7 +408,7 @@ void MathCursor::end(bool sel)
        dump("end 1");
        selHandle(sel);
        macroModeClose();
-       lastcode_ = LM_TC_VAR;
+       lastcode_ = LM_TC_MIN;
        if (!par()->idxEnd(idx(), pos()))
                popRight();
        dump("end 2");
@@ -617,9 +617,9 @@ void MathCursor::macroModeClose()
 }
 
 
-int MathCursor::macroNamePos() const
+MathInset::difference_type MathCursor::macroNamePos() const
 {
-       for (int i = pos() - 1; i >= 0; --i) { 
+       for (MathInset::difference_type i = pos() - 1; i >= 0; --i) { 
                MathAtom & p = array().at(i);
                if (p->code() == LM_TC_TEX && p->getChar() == '\\')
                        return i;
@@ -631,7 +631,8 @@ int MathCursor::macroNamePos() const
 string MathCursor::macroName() const
 {
        string s;
-       for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i) 
+       MathInset::difference_type i = macroNamePos(); 
+       for ( ; i >= 0 && i < int(pos()); ++i) 
                s += array().at(i)->getChar();
        return s;
 }
@@ -858,7 +859,7 @@ bool MathCursor::selection() const
 
 MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
 {
-       for (int i = Cursor_.size() - 1; i >= 0; --i) {
+       for (MathInset::difference_type i = Cursor_.size() - 1; i >= 0; --i) {
                MathGridInset * p = Cursor_[i].par_->asGridInset();
                if (p) {
                        idx = Cursor_[i].idx_;
@@ -1275,6 +1276,7 @@ bool MathCursor::interpret(string const & s)
        return true;
 }
 
+
 bool MathCursor::script(bool up)
 {
        macroModeClose();
@@ -1304,7 +1306,9 @@ bool MathCursor::script(bool up)
 
 bool MathCursor::interpret(char c)
 {
-       //lyxerr << "interpret 2: '" << c << "'\n";
+
+       // Removed super/subscript handling from here  to ::script -MV
+
        // handle macroMode
        if (inMacroMode()) {
                string name = macroName();
@@ -1409,7 +1413,7 @@ bool MathCursor::interpret(char c)
        }
 
        // no special circumstances, so insert the character without any fuss
-       insert(c, lastcode_);
+       insert(c, lastcode_ == LM_TC_MIN ? MathCharInset::nativeCode(c) : lastcode_);
        lastcode_ = LM_TC_MIN;
        return true;
 }
@@ -1449,3 +1453,10 @@ void MathCursor::stripFromLastEqualSign()
 }
 
 
+void MathCursor::setSelection(cursor_type const & where, size_type n)
+{
+       selection_ = true;
+       Anchor_ = where;
+       Cursor_ = where;
+       cursor().pos_ += n;
+}