cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2446 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-08-08 07:12:09 +00:00
parent b155aa1ed5
commit 77d227e06f
3 changed files with 84 additions and 66 deletions

View File

@ -830,8 +830,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
mathcursor->insert(c, LM_TC_TEXTRM); mathcursor->insert(c, LM_TC_TEXTRM);
else if (was_macro) else if (was_macro)
mathcursor->macroModeClose(); mathcursor->macroModeClose();
else if (mathcursor->pop()) else if (mathcursor->popRight())
mathcursor->plainRight(); ;
else { else {
// this would not work if the inset is in an table! // this would not work if the inset is in an table!
//bv->text->cursorRight(bv, true); //bv->text->cursorRight(bv, true);

View File

@ -139,19 +139,26 @@ MathCursor::~MathCursor()
delete imacro_; delete imacro_;
} }
void MathCursor::push(MathInset * par, bool first) void MathCursor::pushLeft(MathInset * par)
{ {
MathCursorPos p; MathCursorPos p;
p.par_ = par; p.par_ = par;
if (first)
par->idxFirst(p.idx_, p.pos_); par->idxFirst(p.idx_, p.pos_);
else Cursor_.push_back(p);
}
void MathCursor::pushRight(MathInset * par)
{
plainLeft();
MathCursorPos p;
p.par_ = par;
par->idxLast(p.idx_, p.pos_); par->idxLast(p.idx_, p.pos_);
Cursor_.push_back(p); Cursor_.push_back(p);
} }
bool MathCursor::pop() bool MathCursor::popLeft()
{ {
if (Cursor_.size() <= 1) if (Cursor_.size() <= 1)
return false; return false;
@ -159,6 +166,15 @@ bool MathCursor::pop()
return true; return true;
} }
bool MathCursor::popRight()
{
if (Cursor_.size() <= 1)
return false;
Cursor_.pop_back();
plainRight();
return true;
}
MathInset * MathCursor::parInset(int i) const MathInset * MathCursor::parInset(int i) const
{ {
@ -258,8 +274,7 @@ bool MathCursor::left(bool sel)
MathInset * p = prevInset(); MathInset * p = prevInset();
if (openable(p, sel, false)) { if (openable(p, sel, false)) {
plainLeft(); pushRight(p);
push(p, false);
return true; return true;
} }
if (pos()) { if (pos()) {
@ -268,7 +283,7 @@ bool MathCursor::left(bool sel)
} }
if (par()->idxLeft(idx(), pos())) if (par()->idxLeft(idx(), pos()))
return true; return true;
if (pop()) if (popLeft())
return true; return true;
return false; return false;
} }
@ -286,20 +301,17 @@ bool MathCursor::right(bool sel)
MathInset * p = nextInset(); MathInset * p = nextInset();
if (openable(p, sel, false)) { if (openable(p, sel, false)) {
push(p, true); pushLeft(p);
return true; return true;
} }
if (pos() != array().size()) { if (pos() != array().size()) {
plainRight(); plainRight();
return true; return true;
} }
if (par()->idxRight(idx(), pos())) { if (par()->idxRight(idx(), pos()))
return true; return true;
} if (popRight())
if (pop()) {
plainRight();
return true; return true;
}
return false; return false;
} }
@ -307,14 +319,14 @@ bool MathCursor::right(bool sel)
void MathCursor::first() void MathCursor::first()
{ {
Cursor_.clear(); Cursor_.clear();
push(outerPar(), true); pushLeft(outerPar());
} }
void MathCursor::last() void MathCursor::last()
{ {
Cursor_.clear(); first();
push(outerPar(), false); end();
} }
@ -354,11 +366,10 @@ void MathCursor::setPos(int x, int y)
MathInset * n = nextInset(); MathInset * n = nextInset();
MathInset * p = prevInset(); MathInset * p = prevInset();
if (openable(n, selection_, true) && n->covers(x, y)) if (openable(n, selection_, true) && n->covers(x, y))
push(n, true); pushLeft(n);
else if (openable(p, selection_, true) && p->covers(x, y)) { else if (openable(p, selection_, true) && p->covers(x, y))
plainLeft(); pushRight(p);
push(p, false); else
} else
break; break;
} }
dump("setPos 2"); dump("setPos 2");
@ -371,7 +382,7 @@ void MathCursor::home()
macroModeClose(); macroModeClose();
clearLastCode(); clearLastCode();
if (!par()->idxHome(idx(), pos())) if (!par()->idxHome(idx(), pos()))
pop(); popLeft();
dump("home 2"); dump("home 2");
} }
@ -381,10 +392,8 @@ void MathCursor::end()
dump("end 1"); dump("end 1");
macroModeClose(); macroModeClose();
clearLastCode(); clearLastCode();
if (!par()->idxEnd(idx(), pos())) { if (!par()->idxEnd(idx(), pos()))
pop(); popRight();
++pos();
}
dump("end 2"); dump("end 2");
} }
@ -485,7 +494,7 @@ void MathCursor::erase()
bool popit; bool popit;
bool removeit; bool removeit;
par()->idxDelete(idx(), popit, removeit); par()->idxDelete(idx(), popit, removeit);
if (popit && pop() && removeit) if (popit && popLeft() && removeit)
plainErase(); plainErase();
return; return;
} }
@ -523,7 +532,7 @@ bool MathCursor::up(bool sel)
pos() = xarray().x2pos(x); pos() = xarray().x2pos(x);
return true; return true;
} }
if (pop()) if (popLeft())
return true; return true;
return false; return false;
} }
@ -533,7 +542,7 @@ bool MathCursor::up(bool sel)
if (p) { if (p) {
int idxx, poss; int idxx, poss;
if (p->idxFirstUp(idxx, poss)) { if (p->idxFirstUp(idxx, poss)) {
push(p, true); pushLeft(p);
idx() = idxx; idx() = idxx;
pos() = poss; pos() = poss;
dump("up 3"); dump("up 3");
@ -545,8 +554,7 @@ bool MathCursor::up(bool sel)
if (p) { if (p) {
int idxx, poss; int idxx, poss;
if (p->idxLastUp(idxx, poss)) { if (p->idxLastUp(idxx, poss)) {
plainLeft(); pushRight(p);
push(p, false);
idx() = idxx; idx() = idxx;
pos() = poss; pos() = poss;
dump("up 4"); dump("up 4");
@ -559,7 +567,7 @@ bool MathCursor::up(bool sel)
pos() = xarray().x2pos(x); pos() = xarray().x2pos(x);
return true; return true;
} }
if (pop()) if (popLeft())
return true; return true;
return false; return false;
} }
@ -577,7 +585,7 @@ bool MathCursor::down(bool sel)
pos() = xarray().x2pos(x); pos() = xarray().x2pos(x);
return true; return true;
} }
if (pop()) if (popLeft())
return true; return true;
return false; return false;
} }
@ -588,7 +596,7 @@ bool MathCursor::down(bool sel)
int idxx = 0; int idxx = 0;
int poss = 0; int poss = 0;
if (p->idxFirstDown(idxx, poss)) { if (p->idxFirstDown(idxx, poss)) {
push(p, true); pushLeft(p);
idx() = idxx; idx() = idxx;
pos() = poss; pos() = poss;
dump("Down 3"); dump("Down 3");
@ -601,8 +609,7 @@ bool MathCursor::down(bool sel)
int idxx = 0; int idxx = 0;
int poss = 0; int poss = 0;
if (p->idxLastDown(idxx, poss)) { if (p->idxLastDown(idxx, poss)) {
plainLeft(); pushRight(p);
push(p, false);
idx() = idxx; idx() = idxx;
pos() = poss; pos() = poss;
dump("Down 4"); dump("Down 4");
@ -615,7 +622,7 @@ bool MathCursor::down(bool sel)
pos() = xarray().x2pos(x); pos() = xarray().x2pos(x);
return true; return true;
} }
if (pop()) if (popLeft())
return true; return true;
return false; return false;
} }
@ -662,8 +669,7 @@ void MathCursor::interpret(string const & s)
} }
insert(p); insert(p);
} }
plainLeft(); pushRight(p);
push(p, true);
if (up) if (up)
p->up(true); p->up(true);
else else
@ -925,7 +931,7 @@ void MathCursor::handleAccent(string const & name)
p->cell(0) = theSelection.glue(); p->cell(0) = theSelection.glue();
} }
insert(p); insert(p);
push(p, true); pushRight(p);
} }
@ -937,8 +943,7 @@ void MathCursor::handleDelim(int l, int r)
p->cell(0) = theSelection.glue(); p->cell(0) = theSelection.glue();
} }
insert(p); insert(p);
plainLeft(); pushRight(p);
push(p, true);
} }
@ -1044,7 +1049,7 @@ void MathCursor::pullArg(bool goright)
// pullArg // pullArg
dump("pullarg"); dump("pullarg");
MathArray a = array(); MathArray a = array();
if (pop()) { if (popLeft()) {
plainErase(); plainErase();
array().insert(pos(), a); array().insert(pos(), a);
if (goright) if (goright)
@ -1066,13 +1071,23 @@ void MathCursor::normalize() const
#endif #endif
MathCursor * it = const_cast<MathCursor *>(this); MathCursor * it = const_cast<MathCursor *>(this);
if (idx() < 0 || idx() > par()->nargs() - 1) if (idx() < 0)
lyxerr << "this should not really happen - 1\n"; lyxerr << "this should not really happen - 1: " << idx() << "\n";
if (idx() >= par()->nargs()) {
lyxerr << "this should not really happen - 2: "
<< idx() << " " << par()->nargs() << "\n";
dump("error 2");
}
it->idx() = max(idx(), 0); it->idx() = max(idx(), 0);
it->idx() = min(idx(), par()->nargs() - 1); it->idx() = min(idx(), par()->nargs() - 1);
if (pos() < 0 || pos() > array().size()) if (pos() < 0)
lyxerr << "this should not really happen - 2\n"; lyxerr << "this should not really happen - 3: " << pos() << "\n";
if (pos() > array().size()) {
lyxerr << "this should not really happen - 4: "
<< pos() << " " << array().size() << "\n";
dump("error 4");
}
it->pos() = max(pos(), 0); it->pos() = max(pos(), 0);
it->pos() = min(pos(), array().size()); it->pos() = min(pos(), array().size());
} }

View File

@ -198,21 +198,14 @@ public:
/// Make sure cursor position is valid /// Make sure cursor position is valid
void normalize() const; void normalize() const;
/// Enter a new MathInset from the front or the back /// enter a MathInset from the front
void push(MathInset * par, bool first); void pushLeft(MathInset * par);
/// Leave current MathInset /// enter a MathInset from the back
bool pop(); void pushRight(MathInset * par);
/// leave current MathInset to the left
//private: bool popLeft();
/// /// leave current MathInset to the left
InsetFormulaBase * const formula_; bool popRight();
///
MathTextCodes lastcode_;
///
MathFuncInset * imacro_;
// Selection stuff
/// do we currently select
bool selection_;
/// ///
MathArray & array() const; MathArray & array() const;
@ -272,6 +265,16 @@ private:
int & pos(); int & pos();
/// ///
int & idx(); int & idx();
///
InsetFormulaBase * const formula_;
///
MathTextCodes lastcode_;
///
MathFuncInset * imacro_;
// Selection stuff
/// do we currently select
bool selection_;
}; };
extern MathCursor * mathcursor; extern MathCursor * mathcursor;