delete imacro_;
}
-void MathCursor::push(MathInset * par, bool first)
+void MathCursor::pushLeft(MathInset * par)
{
MathCursorPos p;
p.par_ = par;
- if (first)
- par->idxFirst(p.idx_, p.pos_);
- else
- par->idxLast(p.idx_, p.pos_);
+ par->idxFirst(p.idx_, p.pos_);
Cursor_.push_back(p);
}
-bool MathCursor::pop()
+void MathCursor::pushRight(MathInset * par)
+{
+ plainLeft();
+ MathCursorPos p;
+ p.par_ = par;
+ par->idxLast(p.idx_, p.pos_);
+ Cursor_.push_back(p);
+}
+
+
+bool MathCursor::popLeft()
{
if (Cursor_.size() <= 1)
return false;
return true;
}
+bool MathCursor::popRight()
+{
+ if (Cursor_.size() <= 1)
+ return false;
+ Cursor_.pop_back();
+ plainRight();
+ return true;
+}
+
MathInset * MathCursor::parInset(int i) const
{
MathInset * p = prevInset();
if (openable(p, sel, false)) {
- plainLeft();
- push(p, false);
+ pushRight(p);
return true;
}
if (pos()) {
}
if (par()->idxLeft(idx(), pos()))
return true;
- if (pop())
+ if (popLeft())
return true;
return false;
}
MathInset * p = nextInset();
if (openable(p, sel, false)) {
- push(p, true);
+ pushLeft(p);
return true;
}
if (pos() != array().size()) {
plainRight();
return true;
}
- if (par()->idxRight(idx(), pos())) {
+ if (par()->idxRight(idx(), pos()))
return true;
- }
- if (pop()) {
- plainRight();
+ if (popRight())
return true;
- }
return false;
}
void MathCursor::first()
{
Cursor_.clear();
- push(outerPar(), true);
+ pushLeft(outerPar());
}
void MathCursor::last()
{
- Cursor_.clear();
- push(outerPar(), false);
+ first();
+ end();
}
MathInset * n = nextInset();
MathInset * p = prevInset();
if (openable(n, selection_, true) && n->covers(x, y))
- push(n, true);
- else if (openable(p, selection_, true) && p->covers(x, y)) {
- plainLeft();
- push(p, false);
- } else
+ pushLeft(n);
+ else if (openable(p, selection_, true) && p->covers(x, y))
+ pushRight(p);
+ else
break;
}
dump("setPos 2");
macroModeClose();
clearLastCode();
if (!par()->idxHome(idx(), pos()))
- pop();
+ popLeft();
dump("home 2");
}
dump("end 1");
macroModeClose();
clearLastCode();
- if (!par()->idxEnd(idx(), pos())) {
- pop();
- ++pos();
- }
+ if (!par()->idxEnd(idx(), pos()))
+ popRight();
dump("end 2");
}
bool popit;
bool removeit;
par()->idxDelete(idx(), popit, removeit);
- if (popit && pop() && removeit)
+ if (popit && popLeft() && removeit)
plainErase();
return;
}
pos() = xarray().x2pos(x);
return true;
}
- if (pop())
+ if (popLeft())
return true;
return false;
}
if (p) {
int idxx, poss;
if (p->idxFirstUp(idxx, poss)) {
- push(p, true);
+ pushLeft(p);
idx() = idxx;
pos() = poss;
dump("up 3");
if (p) {
int idxx, poss;
if (p->idxLastUp(idxx, poss)) {
- plainLeft();
- push(p, false);
+ pushRight(p);
idx() = idxx;
pos() = poss;
dump("up 4");
pos() = xarray().x2pos(x);
return true;
}
- if (pop())
+ if (popLeft())
return true;
return false;
}
pos() = xarray().x2pos(x);
return true;
}
- if (pop())
+ if (popLeft())
return true;
return false;
}
int idxx = 0;
int poss = 0;
if (p->idxFirstDown(idxx, poss)) {
- push(p, true);
+ pushLeft(p);
idx() = idxx;
pos() = poss;
dump("Down 3");
int idxx = 0;
int poss = 0;
if (p->idxLastDown(idxx, poss)) {
- plainLeft();
- push(p, false);
+ pushRight(p);
idx() = idxx;
pos() = poss;
dump("Down 4");
pos() = xarray().x2pos(x);
return true;
}
- if (pop())
+ if (popLeft())
return true;
return false;
}
}
insert(p);
}
- plainLeft();
- push(p, true);
+ pushRight(p);
if (up)
p->up(true);
else
p->cell(0) = theSelection.glue();
}
insert(p);
- push(p, true);
+ pushRight(p);
}
p->cell(0) = theSelection.glue();
}
insert(p);
- plainLeft();
- push(p, true);
+ pushRight(p);
}
// pullArg
dump("pullarg");
MathArray a = array();
- if (pop()) {
+ if (popLeft()) {
plainErase();
array().insert(pos(), a);
if (goright)
#endif
MathCursor * it = const_cast<MathCursor *>(this);
- if (idx() < 0 || idx() > par()->nargs() - 1)
- lyxerr << "this should not really happen - 1\n";
+ if (idx() < 0)
+ 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() = min(idx(), par()->nargs() - 1);
- if (pos() < 0 || pos() > array().size())
- lyxerr << "this should not really happen - 2\n";
+ if (pos() < 0)
+ 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() = min(pos(), array().size());
}
/// Make sure cursor position is valid
void normalize() const;
- /// Enter a new MathInset from the front or the back
- void push(MathInset * par, bool first);
- /// Leave current MathInset
- bool pop();
-
-//private:
- ///
- InsetFormulaBase * const formula_;
- ///
- MathTextCodes lastcode_;
- ///
- MathFuncInset * imacro_;
- // Selection stuff
- /// do we currently select
- bool selection_;
+ /// enter a MathInset from the front
+ void pushLeft(MathInset * par);
+ /// enter a MathInset from the back
+ void pushRight(MathInset * par);
+ /// leave current MathInset to the left
+ bool popLeft();
+ /// leave current MathInset to the left
+ bool popRight();
///
MathArray & array() const;
int & pos();
///
int & idx();
+
+ ///
+ InsetFormulaBase * const formula_;
+ ///
+ MathTextCodes lastcode_;
+ ///
+ MathFuncInset * imacro_;
+ // Selection stuff
+ /// do we currently select
+ bool selection_;
};
extern MathCursor * mathcursor;