small fixes to bugs discoverd by Dekel

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2857 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-10-10 16:35:18 +00:00
parent bcba589379
commit cf3bc4d06e
4 changed files with 105 additions and 64 deletions

View File

@ -309,7 +309,7 @@ UpdatableInset::RESULT
InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
string const & arg) string const & arg)
{ {
//lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action //lyxerr << "InsetFormulaBase::localDispatch: act: " << action
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n"; // << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
if (!mathcursor) if (!mathcursor)

View File

@ -472,7 +472,8 @@ void MathCursor::plainInsert(MathInset * p)
if (inner()) { if (inner()) {
array().insert(pos(), p); array().insert(pos(), p);
++pos(); ++pos();
swap(prevAtom()->nucleus(), nextAtom()->nucleus()); if (prevAtom() && nextAtom()) // should be unnecessary
swap(prevAtom()->nucleus(), nextAtom()->nucleus());
return; return;
} }
@ -514,7 +515,7 @@ void MathCursor::insert(MathInset * p)
void MathCursor::niceInsert(MathInset * p) void MathCursor::niceInsert(MathInset * p)
{ {
if (!p) { if (!p) {
lyxerr << "should not happen\n"; lyxerr << "MathCursor::niceInsert: should not happen\n";
return; return;
} }
selCut(); selCut();
@ -581,8 +582,7 @@ void MathCursor::backspace()
} }
if (pos() == 0) { if (pos() == 0) {
if (size()) pullArg(false);
pullArg(false);
return; return;
} }
@ -728,24 +728,30 @@ void MathCursor::macroModeClose()
{ {
string s = macroName(); string s = macroName();
if (s.size()) { if (s.size()) {
pos() = pos() - s.size() - 1; size_type old = pos();
for (unsigned i = 0; i <= s.size(); ++i) pos() -= s.size();
plainErase(); array().erase(pos(), old);
lastcode_ = LM_TC_VAR; interpret(s);
interpret("\\" + s);
} }
} }
int MathCursor::macroNamePos() const
{
for (int i = pos() - 1; i >= 0; --i) {
MathInset * p = array().at(i)->nucleus();
if (p && p->code() == LM_TC_TEX && p->getChar() == '\\')
return i;
}
return -1;
}
string MathCursor::macroName() const string MathCursor::macroName() const
{ {
string s; string s;
for (int i = pos() - 1; i >= 0; --i) { for (int i = macroNamePos(); i >= 0 && i < int(pos()); ++i)
MathInset * p = array().at(i)->nucleus(); s += array().at(i)->nucleus()->getChar();
if (!p || p->code() != LM_TC_TEX || p->getChar() == '\\')
break;
s = p->getChar() + s;
}
return s; return s;
} }
@ -959,7 +965,7 @@ bool & MathCursor::inner()
bool MathCursor::inMacroMode() const bool MathCursor::inMacroMode() const
{ {
return lastcode_ == LM_TC_TEX; return macroNamePos() != -1;
} }
@ -983,9 +989,25 @@ MathArrayInset * MathCursor::enclosingArray(MathCursor::idx_type & idx) const
void MathCursor::pullArg(bool goright) void MathCursor::pullArg(bool goright)
{ {
// pullArg
dump("pullarg"); dump("pullarg");
MathArray a = array(); MathArray a = array();
MathScriptInset const * p = par()->asScriptInset();
if (p) {
// special handling for scripts
const bool up = p->up();
popLeft();
if (nextAtom()) {
if (up)
nextAtom()->removeUp();
else
nextAtom()->removeDown();
}
++pos();
array().insert(pos(), a);
return;
}
if (popLeft()) { if (popLeft()) {
plainErase(); plainErase();
array().insert(pos(), a); array().insert(pos(), a);
@ -1337,17 +1359,20 @@ MathMatrixInset * MathCursor::outerPar() const
void MathCursor::interpret(string const & s) void MathCursor::interpret(string const & s)
{ {
//lyxerr << "interpret: '" << s << "'\n"; //lyxerr << "interpret 1: '" << s << "'\n";
//lyxerr << "in: " << in_word_set(s) << " \n"; //lyxerr << "in: " << in_word_set(s) << " \n";
if (s.empty()) if (s.empty())
return; return;
char c = s[0]; if (s.size() == 1) {
interpret(s[0]);
return;
}
//lyxerr << "char: '" << c << "' int: " << int(c) << endl; //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl;
//owner_->getIntl()->getTrans().TranslateAndInsert(c, lt); //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt);
//lyxerr << "trans: '" << c << "' int: " << int(c) << endl; //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl;
if (s.size() > 7 && s.substr(0, 7) == "matrix ") { if (s.size() > 7 && s.substr(0, 7) == "matrix ") {
unsigned int m = 1; unsigned int m = 1;
@ -1377,23 +1402,63 @@ void MathCursor::interpret(string const & s)
return; return;
} }
if (s.size() > 1) { niceInsert(createMathInset(s.substr(1)));
niceInsert(createMathInset(s.substr(1))); }
void MathCursor::interpret(char c)
{
//lyxerr << "interpret 2: '" << c << "'\n";
if (inMacroMode()) {
string name = macroName();
if (name == "\\" && c == '#') {
insert(c, LM_TC_TEX);
return;
}
if (name == "\\" && c == '\\') {
backspac/();
interpret("\\backslash");
return;
}
if (name == "\\#" && '1' <= c && c <= '9') {
insert(c, LM_TC_TEX);
macroModeClose();
return;
}
if (isalpha(c)) {
insert(c, LM_TC_TEX);
return;
}
if (name == "\\") {
insert(c, LM_TC_TEX);
macroModeClose();
return;
}
macroModeClose();
return; return;
} }
// no macro mode
// we got just a single char now
if (c == '^' || c == '_') { if (c == '^' || c == '_') {
const bool up = (s[0] == '^'); const bool up = (c == '^');
const bool in = inner();
selCut(); selCut();
if (inner()) if (in)
++pos(); ++pos();
if (!prevAtom()) if (!prevAtom())
insert(0); insert(0);
MathInset * par = prevAtom()->ensure(up); MathInset * par = prevAtom()->ensure(up);
pushRight(par); if (in)
pushLeft(par);
else
pushRight(par);
selPaste(); selPaste();
return; return;
} }
@ -1407,12 +1472,6 @@ void MathCursor::interpret(string const & s)
} }
if (c == ' ') { if (c == ' ') {
if (inMacroMode()) {
macroModeClose();
lastcode_ = LM_TC_VAR;
return;
}
MathSpaceInset * p = prevSpaceInset(); MathSpaceInset * p = prevSpaceInset();
if (p) { if (p) {
p->incSpace(); p->incSpace();
@ -1429,41 +1488,17 @@ void MathCursor::interpret(string const & s)
return; return;
} }
if (lastcode_ != LM_TC_TEX && strchr("{}", c)) { if (strchr("{}", c)) {
insert(c, LM_TC_TEX); insert(c, LM_TC_TEX);
return; return;
} }
if (lastcode_ != LM_TC_TEX && strchr("#$%", c)) { if (strchr("#$%", c)) {
insert(new MathSpecialCharInset(c)); insert(new MathSpecialCharInset(c));
lastcode_ = LM_TC_VAR; lastcode_ = LM_TC_VAR;
return; return;
} }
if (lastcode_ == LM_TC_TEX) {
if (macroName().empty()) {
insert(c, LM_TC_TEX);
if (!isalpha(c) && c != '#') {
macroModeClose();
lastcode_ = LM_TC_VAR;
}
} else {
if ('1' <= c && c <= '9' && macroName() == "#") {
insert(c, LM_TC_TEX);
macroModeClose();
lastcode_ = LM_TC_VAR;
}
else if (isalpha(c)) {
insert(c, LM_TC_TEX);
}
else {
macroModeClose();
lastcode_ = LM_TC_VAR;
}
}
return;
}
if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) { if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
static char const greekl[][26] = static char const greekl[][26] =
{"alpha", "beta", "chi", "delta", "epsilon", "phi", {"alpha", "beta", "chi", "delta", "epsilon", "phi",
@ -1494,7 +1529,6 @@ void MathCursor::interpret(string const & s)
} }
if (c == '\\') { if (c == '\\') {
lastcode_ = LM_TC_TEX;
insert(c, LM_TC_TEX); insert(c, LM_TC_TEX);
//bv->owner()->message(_("TeX mode")); //bv->owner()->message(_("TeX mode"));
return; return;

View File

@ -141,6 +141,8 @@ public:
/// ///
void interpret(string const &); void interpret(string const &);
/// ///
void interpret(char);
///
void setSize(MathStyles); void setSize(MathStyles);
/// ///
bool toggleLimits(); bool toggleLimits();
@ -278,6 +280,8 @@ private:
/// ///
string macroName() const; string macroName() const;
/// ///
int macroNamePos() const;
///
void insert(char, MathTextCodes t); void insert(char, MathTextCodes t);
/// can we enter the inset? /// can we enter the inset?
bool openable(MathInset *, bool selection) const; bool openable(MathInset *, bool selection) const;

View File

@ -70,6 +70,9 @@ MathInset * createMathInset(string const & s)
if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9') if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
return new MathMacroArgument(s[1] - '0'); return new MathMacroArgument(s[1] - '0');
if (s.size() == 3 && s[0] == '\\' && s[1] == '#' && s[2] >= '1' && s[2] <= '9')
return new MathMacroArgument(s[2] - '0');
latexkeys const * l = in_word_set(s); latexkeys const * l = in_word_set(s);
if (l) if (l)
return createMathInset(l); return createMathInset(l);