diff --git a/src/mathed/array.C b/src/mathed/array.C index 5b9b7cbbda..9460af4204 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -52,7 +52,7 @@ MathAtom const * MathArray::at(int pos) const void MathArray::insert(int pos, MathInset * p) { //cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n"; - // inserting th + // inserting here invalidates the pointer! bf_.insert(begin() + pos, MathAtom(p)); //cerr << "\n 2: "; p->write(cerr, true); cerr << p << "\n"; } diff --git a/src/mathed/math_atom.C b/src/mathed/math_atom.C index 33ae8e4bf7..217f109069 100644 --- a/src/mathed/math_atom.C +++ b/src/mathed/math_atom.C @@ -315,9 +315,9 @@ void MathAtom::draw(Painter & pain, int x, int y) const if (nucleus()) nucleus()->draw(pain, x + dxx(), y); if (up()) - up()->xcell(0).draw(pain, x + dx1(), y - dy1()); + up()->draw(pain, x + dx1(), y - dy1()); if (down()) - down()->xcell(0).draw(pain, x + dx0(), y + dy0()); + down()->draw(pain, x + dx0(), y + dy0()); } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index f9a8524493..e334f75eba 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -232,22 +232,34 @@ bool MathCursor::openable(MathInset * p, bool sel) const } -bool MathCursor::positionable(MathInset * p, bool sel) const +MathInset * MathCursor::positionable(MathAtom * t, int x, int y) const { - if (!p) - return false; + if (!t) + return 0; - if (!p->nargs()) - return false; - - if (sel) { + if (selection_) { // we can't move into anything new during selection if (Cursor_.size() == Anchor_.size()) - return false; - if (p != Anchor_[Cursor_.size()].par_) - return false; + return 0; + //if (t != Anchor_[Cursor_.size()].par_) + // return 0; } - return true; + + MathInset * p; + + p = t->nucleus(); + if (p && p->nargs() && p->covers(x, y)) + return p; + + p = t->up(); + if (p && p->nargs() && p->covers(x, y)) + return p; + + p = t->down(); + if (p && p->nargs() && p->covers(x, y)) + return p; + + return 0; } @@ -327,7 +339,7 @@ void MathCursor::last() void MathCursor::setPos(int x, int y) { - dump("setPos 1"); + //dump("setPos 1"); //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n"; macroModeClose(); @@ -339,7 +351,7 @@ void MathCursor::setPos(int x, int y) while (1) { idx() = -1; cursor().pos_ = -1; - //lyxerr << "found idx: " << idx_ << " cursor: " << pos() << "\n"; + //lyxerr << "found idx: " << idx() << " cursor: " << pos() << "\n"; int distmin = 1 << 30; // large enough for (int i = 0; i < par()->nargs(); ++i) { MathXArray const & ar = par()->xcell(i); @@ -351,23 +363,21 @@ void MathCursor::setPos(int x, int y) //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy // << " c: " << c << " xo: " << ar.xo() << "\n"; if (yy + xx <= distmin) { - distmin = yy + xx; - idx() = i; - pos() = c; + distmin = yy + xx; + idx() = i; + pos() = c; } } //lyxerr << "found idx: " << idx() << " cursor: " // << pos() << "\n"; - MathInset * n = nextInset(); - MathInset * p = prevInset(); - if (positionable(n, selection_) && n->covers(x, y)) - pushLeft(n); - else if (positionable(p, selection_) && p->covers(x, y)) + if (MathInset * p = positionable(nextAtom(), x, y)) + pushLeft(p); + else if (MathInset * p = positionable(prevAtom(), x, y)) pushRight(p); else break; } - dump("setPos 2"); + //dump("setPos 2"); } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 3b9d2eb491..34f9333789 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -259,7 +259,7 @@ private: /// can we enter the inset? bool openable(MathInset *, bool selection) const; /// can the setPos routine enter that inset? - bool positionable(MathInset *, bool selection) const; + MathInset * positionable(MathAtom *, int x, int y) const; /// write access to cursor cell position int & pos(); /// write access to cursor cell index diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index e9e4bb654b..e132d5ce50 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -267,6 +267,8 @@ void MathInset::push_back(MathInset *) bool MathInset::covers(int x, int y) const { + //lyxerr << "cover? p: " << this << " x: " << x << " y: " << y + // << " xo_: " << xo_ << " yo_: " << yo_ << endl; return x >= xo_ && x <= xo_ + width() && diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index a8bf9d6b7b..019c045e37 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -1,6 +1,5 @@ #include #include "debug.h" -#include "support.h" #include "support/LOstream.h" #ifdef __GNUG__ @@ -20,92 +19,6 @@ MathInset * MathScriptInset::clone() const return new MathScriptInset(*this); } -#if 0 - -bool MathScriptInset::idxUp(int & idx, int & pos) const -{ - if (idx == 0 || !up()) - return false; - idx = 0; - pos = 0; - return true; -} - -bool MathScriptInset::idxDown(int & idx, int & pos) const -{ - if (idx == 1 || !down()) - return false; - idx = 1; - pos = 0; - return true; -} - -bool MathScriptInset::idxFirst(int & idx, int & pos) const -{ - idx = up() ? 0 : 1; - pos = 0; - return true; -} - -bool MathScriptInset::idxLast(int & idx, int & pos) const -{ - idx = down() ? 1 : 0; - pos = cell(idx).size(); - return true; -} - - -bool MathScriptInset::idxFirstUp(int & idx, int & pos) const -{ - if (!up()) - return false; - idx = 0; - pos = 0; - return true; -} - - -bool MathScriptInset::idxFirstDown(int & idx, int & pos) const -{ - if (!down()) - return false; - idx = 1; - pos = 0; - return true; -} - - -bool MathScriptInset::idxLastUp(int & idx, int & pos) const -{ - if (!up()) - return false; - idx = 0; - pos = cell(idx).size(); - return true; -} - - -bool MathScriptInset::idxLastDown(int & idx, int & pos) const -{ - if (!down()) - return false; - idx = 1; - pos = cell(idx).size(); - return true; -} - -void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit) -{ - if (idx == 0) - up(false); - else - down(false); - popit = true; - deleteit = !(up() || down()); -} - -#endif - void MathScriptInset::write(std::ostream & os, bool fragile) const {