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
This commit is contained in:
André Pönitz 2001-11-13 08:03:52 +00:00
parent 29663cf58f
commit 98d0501e77
3 changed files with 35 additions and 32 deletions

View File

@ -594,7 +594,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
case LFUN_SELFINSERT: case LFUN_SELFINSERT:
if (!arg.empty()) { if (!arg.empty()) {
bv->lockedInsetStoreUndo(Undo::EDIT); bv->lockedInsetStoreUndo(Undo::EDIT);
mathcursor->interpret(arg); result = mathcursor->interpret(arg) ? DISPATCHED : FINISHED_RIGHT;
updateLocal(bv, true); updateLocal(bv, true);
} }
break; break;

View 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"; //lyxerr << "interpret 1: '" << s << "'\n";
if (s.empty()) if (s.empty())
return; return true;
if (s.size() == 1) { if (s.size() == 1)
interpret(s[0]); return interpret(s[0]);
return;
}
//lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl; //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
//owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt); //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
@ -1292,7 +1290,7 @@ void MathCursor::interpret(string const & s)
is >> n; is >> n;
n = std::max(1u, n); n = std::max(1u, n);
niceInsert(MathAtom(new MathCasesInset(n))); niceInsert(MathAtom(new MathCasesInset(n)));
return; return true;
} }
if (s.size() >= 6 && s.substr(0, 6) == "matrix") { if (s.size() >= 6 && s.substr(0, 6) == "matrix") {
@ -1306,7 +1304,7 @@ void MathCursor::interpret(string const & s)
n = std::max(1u, n); n = std::max(1u, n);
v_align += 'c'; v_align += 'c';
niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align))); niceInsert(MathAtom(new MathArrayInset(m, n, v_align[0], h_align)));
return; return true;
} }
if (s == "\\over" || s == "\\choose" || s == "\\atop") { if (s == "\\over" || s == "\\choose" || s == "\\atop") {
@ -1317,14 +1315,15 @@ void MathCursor::interpret(string const & s)
niceInsert(t); niceInsert(t);
popRight(); popRight();
left(); left();
return; return true;
} }
niceInsert(createMathInset(s.substr(1))); niceInsert(createMathInset(s.substr(1)));
return true;
} }
void MathCursor::interpret(char c) bool MathCursor::interpret(char c)
{ {
//lyxerr << "interpret 2: '" << c << "'\n"; //lyxerr << "interpret 2: '" << c << "'\n";
if (c == '^' || c == '_') { if (c == '^' || c == '_') {
@ -1350,7 +1349,7 @@ void MathCursor::interpret(char c)
} }
selPaste(); selPaste();
dump("1"); dump("1");
return; return true;
} }
@ -1360,34 +1359,34 @@ void MathCursor::interpret(char c)
if (name == "\\" && c == '#') { if (name == "\\" && c == '#') {
insert(c, LM_TC_TEX); insert(c, LM_TC_TEX);
return; return true;
} }
if (name == "\\" && c == '\\') { if (name == "\\" && c == '\\') {
backspace(); backspace();
interpret("\\backslash"); interpret("\\backslash");
return; return true;
} }
if (name == "\\#" && '1' <= c && c <= '9') { if (name == "\\#" && '1' <= c && c <= '9') {
insert(c, LM_TC_TEX); insert(c, LM_TC_TEX);
macroModeClose(); macroModeClose();
return; return true;
} }
if (isalpha(c)) { if (isalpha(c)) {
insert(c, LM_TC_TEX); insert(c, LM_TC_TEX);
return; return true;
} }
if (name == "\\") { if (name == "\\") {
insert(c, LM_TC_TEX); insert(c, LM_TC_TEX);
macroModeClose(); macroModeClose();
return; return true;
} }
macroModeClose(); macroModeClose();
return; return true;
} }
if (selection_) if (selection_)
@ -1398,62 +1397,66 @@ void MathCursor::interpret(char c)
// the still allows typing '<space>a<space>' and deleting the 'a', but // the still allows typing '<space>a<space>' and deleting the 'a', but
// it is better than nothing // it is better than nothing
if (hasPrevAtom() && prevAtom()->getChar() == ' ') if (hasPrevAtom() && prevAtom()->getChar() == ' ')
return; return true;
insert(c, LM_TC_TEXTRM); insert(c, LM_TC_TEXTRM);
return; return true;
} }
if (c == ' ') { if (c == ' ') {
if (hasPrevAtom() && prevAtom()->asSpaceInset()) { if (hasPrevAtom() && prevAtom()->asSpaceInset()) {
prevAtom()->asSpaceInset()->incSpace(); prevAtom()->asSpaceInset()->incSpace();
return; return true;
} }
mathcursor->popRight(); if (mathcursor->popRight())
return; return true;
// if are at the very end, leave the formula
return pos() != size();
} }
/* /*
if (strchr("{}", c)) { if (strchr("{}", c)) {
insert(c, LM_TC_TEX); insert(c, LM_TC_TEX);
return; return true;
} }
*/ */
if (c == '{') { if (c == '{') {
niceInsert(MathAtom(new MathBraceInset)); niceInsert(MathAtom(new MathBraceInset));
return; return true;
} }
if (c == '}') { if (c == '}') {
return; return true;
} }
if (strchr("#$%", c)) { if (strchr("#$%", c)) {
insert(MathAtom(new MathSpecialCharInset(c))); insert(MathAtom(new MathSpecialCharInset(c)));
lastcode_ = LM_TC_VAR; lastcode_ = LM_TC_VAR;
return; return true;
} }
if (isalpha(c) && lastcode_ == LM_TC_GREEK) { if (isalpha(c) && lastcode_ == LM_TC_GREEK) {
insert(c, LM_TC_VAR); insert(c, LM_TC_VAR);
return; return true;
} }
if (isalpha(c) && lastcode_ == LM_TC_GREEK1) { if (isalpha(c) && lastcode_ == LM_TC_GREEK1) {
insert(c, LM_TC_VAR); insert(c, LM_TC_VAR);
lastcode_ = LM_TC_VAR; lastcode_ = LM_TC_VAR;
return; return true;
} }
if (c == '\\') { if (c == '\\') {
insert(c, LM_TC_TEX); insert(c, LM_TC_TEX);
//bv->owner()->message(_("TeX mode")); //bv->owner()->message(_("TeX mode"));
return; return true;
} }
// no special circumstances, so insert the character without any fuss // no special circumstances, so insert the character without any fuss
insert(c, LM_TC_MIN); insert(c, LM_TC_MIN);
return true;
} }

View File

@ -136,9 +136,9 @@ public:
/// ///
size_type size() const; size_type size() const;
/// ///
void interpret(string const &); bool interpret(string const &);
/// ///
void interpret(char); bool interpret(char);
/// ///
bool toggleLimits(); bool toggleLimits();
/// ///