From 98d0501e77a26e1435c08dc36674fabc19a19ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 13 Nov 2001 08:03:52 +0000 Subject: [PATCH] make 'space' leave the formula if pressed at the very end git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3014 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 2 +- src/mathed/math_cursor.C | 61 +++++++++++++++++++++------------------- src/mathed/math_cursor.h | 4 +-- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index a7a24cd2f5..124c64e395 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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; diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 51230e0066..2b4db8d149 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -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 'a' 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; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index cd110890ed..ff4e92e6a4 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -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(); ///