]> git.lyx.org Git - features.git/commitdiff
make 'space' leave the formula if pressed at the very end
authorAndré Pönitz <poenitz@gmx.net>
Tue, 13 Nov 2001 08:03:52 +0000 (08:03 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 13 Nov 2001 08:03:52 +0000 (08:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3014 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h

index a7a24cd2f5e122ea5be371d126573e312b8ee466..124c64e39584d81e8d4d711c173af4e5808ee7ce 100644 (file)
@@ -594,7 +594,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
        case LFUN_SELFINSERT:
                if (!arg.empty()) {
                        bv->lockedInsetStoreUndo(Undo::EDIT);
-                       mathcursor->interpret(arg);
+                       result = mathcursor->interpret(arg) ? DISPATCHED : FINISHED_RIGHT;
                        updateLocal(bv, true);
                }
                break;
index 51230e00660d6892b64a5eb61db7188f0a706cba..2b4db8d14919dfa8cde2a501f40054ced87a509f 100644 (file)
@@ -1271,16 +1271,14 @@ bool MathCursor::idxRight()
 }
 
 
-void MathCursor::interpret(string const & s)
+bool MathCursor::interpret(string const & s)
 {
        //lyxerr << "interpret 1: '" << s << "'\n";
        if (s.empty())
-               return;
+               return true;
 
-       if (s.size() == 1) {
-               interpret(s[0]);
-               return;
-       }
+       if (s.size() == 1)
+               return interpret(s[0]);
 
        //lyxerr << "char: '" << s[0] << "'  int: " << int(s[0]) << endl;
        //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);   
@@ -1292,7 +1290,7 @@ void MathCursor::interpret(string const & s)
                is >> n;
                n = std::max(1u, n);
                niceInsert(MathAtom(new MathCasesInset(n)));
-               return;
+               return true;
        }
 
        if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
@@ -1306,7 +1304,7 @@ void MathCursor::interpret(string const & s)
                n = std::max(1u, n);
                v_align += 'c';
                niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
-               return;
+               return true;
        }
 
        if (s == "\\over" || s == "\\choose" || s == "\\atop") {
@@ -1317,14 +1315,15 @@ void MathCursor::interpret(string const & s)
                niceInsert(t);
                popRight();
                left();
-               return;
+               return true;
        }
 
        niceInsert(createMathInset(s.substr(1)));
+       return true;
 }
 
 
-void MathCursor::interpret(char c)
+bool MathCursor::interpret(char c)
 {
        //lyxerr << "interpret 2: '" << c << "'\n";
        if (c == '^' || c == '_') {
@@ -1350,7 +1349,7 @@ void MathCursor::interpret(char c)
                }
                selPaste();
                dump("1");
-               return;
+               return true;
        }
 
 
@@ -1360,34 +1359,34 @@ void MathCursor::interpret(char c)
 
                if (name == "\\" && c == '#') {
                        insert(c, LM_TC_TEX);
-                       return;
+                       return true;
                }
 
                if (name == "\\" && c == '\\') {
                        backspace();
                        interpret("\\backslash");
-                       return;
+                       return true;
                }
 
                if (name == "\\#" && '1' <= c && c <= '9') {
                        insert(c, LM_TC_TEX);
                        macroModeClose();
-                       return;
+                       return true;
                }
 
                if (isalpha(c)) {
                        insert(c, LM_TC_TEX);
-                       return;
+                       return true;
                }
 
                if (name == "\\") {
                        insert(c, LM_TC_TEX);
                        macroModeClose();
-                       return;
+                       return true;
                }
 
                macroModeClose();
-               return;
+               return true;
        }
 
        if (selection_)
@@ -1398,62 +1397,66 @@ void MathCursor::interpret(char c)
                // the still allows typing  '<space>a<space>' and deleting the 'a', but
                // it is better than nothing
                if (hasPrevAtom() && prevAtom()->getChar() == ' ')
-                       return;
+                       return true;
                insert(c, LM_TC_TEXTRM);
-               return;
+               return true;
        }
 
        if (c == ' ') {
                if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
                        prevAtom()->asSpaceInset()->incSpace();
-                       return;
+                       return true;
                }
+       
+               if (mathcursor->popRight())
+                       return true;
 
-               mathcursor->popRight();
-               return;
+               // if are at the very end, leave the formula
+               return pos() != size();
        }
 
 /*
        if (strchr("{}", c)) {
                insert(c, LM_TC_TEX);
-               return;
+               return true;
        }
 */
 
        if (c == '{') {
                niceInsert(MathAtom(new MathBraceInset));
-               return;
+               return true;
        }
 
        if (c == '}') {
-               return;
+               return true;
        }
 
        if (strchr("#$%", c)) {
                insert(MathAtom(new MathSpecialCharInset(c)));  
                lastcode_ = LM_TC_VAR;
-               return;
+               return true;
        }
 
        if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
                insert(c, LM_TC_VAR);
-               return
+               return true;
        }
 
        if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
                insert(c, LM_TC_VAR);
                lastcode_ = LM_TC_VAR;
-               return
+               return true;
        }
 
        if (c == '\\') {
                insert(c, LM_TC_TEX);
                //bv->owner()->message(_("TeX mode"));
-               return; 
+               return true;    
        }
 
        // no special circumstances, so insert the character without any fuss
        insert(c, LM_TC_MIN);
+       return true;
 }
 
 
index cd110890ede96a22459883556c483a4130f8dd22..ff4e92e6a4cb19576dbd4275aa905b14b5ca8333 100644 (file)
@@ -136,9 +136,9 @@ public:
        ///
        size_type size() const;
        ///
-       void interpret(string const &);
+       bool interpret(string const &);
        ///
-       void interpret(char);
+       bool interpret(char);
        ///
        bool toggleLimits();
        ///