prepare infrastructure for multicell selection

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2242 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-07-13 16:06:10 +00:00
parent 0c94bf1d21
commit 87f0ddf453
3 changed files with 175 additions and 169 deletions

View File

@ -580,7 +580,10 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
bv->updateInset(this, true); bv->updateInset(this, true);
break; break;
} }
mathcursor->plainLeft(); if (mathcursor->InMacroMode())
mathcursor->Left();
else
mathcursor->plainLeft();
// fall through... // fall through...
case LFUN_DELETE: case LFUN_DELETE:

View File

@ -86,13 +86,12 @@ MathCursor::MathCursor(InsetFormulaBase * formula)
void MathCursor::push(MathInset * par, bool first) void MathCursor::push(MathInset * par, bool first)
{ {
path_.push_back(MathIter()); path_.push_back(cursor_);
path_.back().par_ = par_; cursor_.par_ = par;
path_.back().idx_ = idx_; if (first)
path_.back().cursor_ = cursor_; par->idxFirst(cursor_.idx_, cursor_.pos_);
dump("Pushed:"); else
par_ = par; par->idxLast(cursor_.idx_, cursor_.pos_);
first ? par_->idxFirst(idx_, cursor_) : par_->idxLast(idx_, cursor_);
} }
@ -100,9 +99,7 @@ bool MathCursor::pop()
{ {
if (path_.empty()) if (path_.empty())
return false; return false;
par_ = path_.back().par_; cursor_ = path_.back();
idx_ = path_.back().idx_;
cursor_ = path_.back().cursor_;
dump("Popped:"); dump("Popped:");
path_.pop_back(); path_.pop_back();
return true; return true;
@ -119,10 +116,12 @@ void MathCursor::dump(char const * what) const
return; return;
lyxerr << "MC: " << what lyxerr << "MC: " << what
<< " cursor: " << cursor_ << " cursor.pos: " << cursor_.pos_
<< " anchor: " << anchor_ << " cursor.idx: " << cursor_.idx_
<< " idx: " << idx_ << " cursor.par: " << cursor_.par_
<< " par: " << par_ << " anchor.pos: " << anchor_.pos_
<< " anchor.idx: " << anchor_.idx_
<< " anchor.par: " << anchor_.par_
<< " sel: " << selection << " sel: " << selection
<< " data: " << array() << " data: " << array()
<< "\n"; << "\n";
@ -138,8 +137,8 @@ void MathCursor::seldump(char const * str) const
<< str << "\nselarray: " << selarray; << str << "\nselarray: " << selarray;
for (unsigned int i = 0; i < path_.size(); ++i) for (unsigned int i = 0; i < path_.size(); ++i)
lyxerr << path_[i].par_ << "\n'" << path_[i].par_->cell(0) << "'\n"; lyxerr << path_[i].par_ << "\n'" << path_[i].par_->cell(0) << "'\n";
lyxerr << "\ncursor: " << cursor_; lyxerr << "\ncursor.pos_: " << cursor_.pos_;
lyxerr << "\nanchor: " << anchor_; lyxerr << "\nanchor.pos_: " << anchor_.pos_;
lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n"; lyxerr << "\n===================^^^^^^^^^^^^=====================\n\n\n";
} }
@ -149,13 +148,13 @@ bool MathCursor::isInside(MathInset * p) const
for (unsigned i = 0; i < path_.size(); ++i) for (unsigned i = 0; i < path_.size(); ++i)
if (parInset(i) == p) if (parInset(i) == p)
return true; return true;
return par_ == p; return cursor_.par_ == p;
} }
bool MathCursor::plainLeft() bool MathCursor::plainLeft()
{ {
return array().prev(cursor_); return array().prev(cursor_.pos_);
} }
bool MathCursor::Left(bool sel) bool MathCursor::Left(bool sel)
@ -176,24 +175,24 @@ bool MathCursor::Left(bool sel)
bool result = false; bool result = false;
if (selection) { if (selection) {
result = array().prev(cursor_); result = array().prev(cursor_.pos_);
if (!result && pop()) { if (!result && pop()) {
anchor_ = cursor_; anchor_.pos_ = cursor_.pos_;
result = array().next(anchor_); result = array().next(anchor_.pos_);
} }
} else { } else {
MathInset * p = prevInset(); MathInset * p = prevInset();
if (p && p->isActive()) { if (p && p->isActive()) {
// We have to move deeper into the previous inset // We have to move deeper into the previous inset
array().prev(cursor_); array().prev(cursor_.pos_);
push(p, false); push(p, false);
result = true; result = true;
} else { } else {
// The common case, where we are not // The common case, where we are not
// entering a deeper inset // entering a deeper inset
result = array().prev(cursor_); result = array().prev(cursor_.pos_);
if (!result) { if (!result) {
if (par_->idxLeft(idx_, cursor_)) { if (cursor_.par_->idxLeft(cursor_.idx_, cursor_.pos_)) {
result = true; result = true;
} else if (pop()) { } else if (pop()) {
result = true; result = true;
@ -208,7 +207,7 @@ bool MathCursor::Left(bool sel)
bool MathCursor::plainRight() bool MathCursor::plainRight()
{ {
return array().next(cursor_); return array().next(cursor_.pos_);
} }
@ -225,10 +224,10 @@ bool MathCursor::Right(bool sel)
bool result = false; bool result = false;
if (selection) { if (selection) {
result = array().next(cursor_); result = array().next(cursor_.pos_);
if (!result && pop()) { if (!result && pop()) {
anchor_ = cursor_; anchor_.pos_ = cursor_.pos_;
result = array().next(cursor_); result = array().next(cursor_.pos_);
} }
} else { } else {
MathInset * p = nextInset(); MathInset * p = nextInset();
@ -236,13 +235,13 @@ bool MathCursor::Right(bool sel)
push(p, true); push(p, true);
result = true; result = true;
} else { } else {
result = array().next(cursor_); result = array().next(cursor_.pos_);
if (!result) { if (!result) {
if (par_->idxRight(idx_, cursor_)) { if (cursor_.par_->idxRight(cursor_.idx_, cursor_.pos_)) {
result = true; result = true;
} else if (pop()) { } else if (pop()) {
result = true; result = true;
array().next(cursor_); array().next(cursor_.pos_);
} }
} }
} }
@ -254,23 +253,23 @@ bool MathCursor::Right(bool sel)
void MathCursor::first() void MathCursor::first()
{ {
selection = false; selection = false;
par_ = formula_->par(); cursor_.par_ = formula_->par();
idx_ = 0; cursor_.idx_ = 0;
cursor_ = 0; cursor_.pos_ = 0;
anchor_ = 0; anchor_.pos_ = 0;
par_->idxFirst(idx_, cursor_); cursor_.par_->idxFirst(cursor_.idx_, cursor_.pos_);
} }
void MathCursor::last() void MathCursor::last()
{ {
selection = false; selection = false;
par_ = formula_->par(); cursor_.par_ = formula_->par();
idx_ = 0; cursor_.idx_ = 0;
cursor_ = 0; cursor_.pos_ = 0;
anchor_ = 0; anchor_.pos_ = 0;
par_->idxLast(idx_, cursor_); cursor_.par_->idxLast(cursor_.idx_, cursor_.pos_);
} }
@ -283,15 +282,15 @@ void MathCursor::SetPos(int x, int y)
lastcode = LM_TC_MIN; lastcode = LM_TC_MIN;
path_.clear(); path_.clear();
par_ = formula()->par(); cursor_.par_ = formula()->par();
while (1) { while (1) {
idx_ = -1; cursor_.idx_ = -1;
cursor_ = -1; cursor_.pos_ = -1;
//lyxerr << "found idx: " << idx_ << " cursor: " << cursor_ << "\n"; //lyxerr << "found idx: " << idx_ << " cursor: " << cursor_.pos_ << "\n";
int distmin = 1 << 30; // large enough int distmin = 1 << 30; // large enough
for (int i = 0; i < par_->nargs(); ++i) { for (int i = 0; i < cursor_.par_->nargs(); ++i) {
MathXArray const & ar = par_->xcell(i); MathXArray const & ar = cursor_.par_->xcell(i);
int x1 = x - ar.xo(); int x1 = x - ar.xo();
int y1 = y - ar.yo(); int y1 = y - ar.yo();
int c = ar.x2pos(x1); int c = ar.x2pos(x1);
@ -300,18 +299,18 @@ void MathCursor::SetPos(int x, int y)
//lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
// << " c: " << c << " xo: " << ar.xo() << "\n"; // << " c: " << c << " xo: " << ar.xo() << "\n";
if (yy + xx <= distmin) { if (yy + xx <= distmin) {
distmin = yy + xx; distmin = yy + xx;
idx_ = i; cursor_.idx_ = i;
cursor_ = c; cursor_.pos_ = c;
} }
} }
lyxerr << "found idx: " << idx_ << " cursor: " << cursor_ << "\n"; lyxerr << "found idx: " << cursor_.idx_ << " cursor: " << cursor_.pos_ << "\n";
MathInset * n = nextInset(); MathInset * n = nextInset();
MathInset * p = prevInset(); MathInset * p = prevInset();
if (n && (n->isActive() || n->isUpDownInset()) && n->covers(x, y)) if (n && (n->isActive() || n->isUpDownInset()) && n->covers(x, y))
push(n, true); push(n, true);
else if (p && (p->isActive() || p->isUpDownInset()) && p->covers(x, y)) { else if (p && (p->isActive() || p->isUpDownInset()) && p->covers(x, y)) {
array().prev(cursor_); array().prev(cursor_.pos_);
push(p, false); push(p, false);
} else } else
break; break;
@ -326,7 +325,7 @@ void MathCursor::Home()
if (macro_mode) if (macro_mode)
MacroModeClose(); MacroModeClose();
clearLastCode(); clearLastCode();
if (!par_->idxHome(idx_, cursor_)) if (!cursor_.par_->idxHome(cursor_.idx_, cursor_.pos_))
pop(); pop();
dump("Home 2"); dump("Home 2");
} }
@ -338,9 +337,9 @@ void MathCursor::End()
if (macro_mode) if (macro_mode)
MacroModeClose(); MacroModeClose();
clearLastCode(); clearLastCode();
if (!par_->idxEnd(idx_, cursor_)) { if (!cursor_.par_->idxEnd(cursor_.idx_, cursor_.pos_)) {
pop(); pop();
array().next(cursor_); array().next(cursor_.pos_);
} }
dump("End 2"); dump("End 2");
} }
@ -366,8 +365,8 @@ void MathCursor::insert(char c, MathTextCodes t)
} }
} }
array().insert(cursor_, c, t); array().insert(cursor_.pos_, c, t);
array().next(cursor_); array().next(cursor_.pos_);
lastcode = t; lastcode = t;
} }
@ -384,8 +383,8 @@ void MathCursor::insert(MathInset * p)
SelDel(); SelDel();
} }
array().insert(cursor_, p); array().insert(cursor_.pos_, p);
array().next(cursor_); array().next(cursor_.pos_);
} }
@ -400,14 +399,14 @@ void MathCursor::Delete()
return; return;
} }
if (cursor_ < array().size()) if (cursor_.pos_ < array().size())
array().erase(cursor_); array().erase(cursor_.pos_);
// delete empty cells if necessary // delete empty cells if necessary
if (cursor_ == 0 && array().size() == 0) { if (cursor_.pos_ == 0 && array().size() == 0) {
bool popit; bool popit;
bool removeit; bool removeit;
par_->idxDelete(idx_, popit, removeit); cursor_.par_->idxDelete(cursor_.idx_, popit, removeit);
if (popit && pop() && removeit) if (popit && pop() && removeit)
Delete(); Delete();
} }
@ -415,7 +414,7 @@ void MathCursor::Delete()
#ifdef WITH_WARNINGS #ifdef WITH_WARNINGS
#warning pullArg disabled #warning pullArg disabled
#endif #endif
//if (cursor_ == 0 && !path_.empty()) { //if (cursor_.pos_ == 0 && !path_.empty()) {
// lyxerr << "Delete: popping...\n"; // lyxerr << "Delete: popping...\n";
// pop(); // pop();
//} //}
@ -433,8 +432,8 @@ void MathCursor::DelLine()
return; return;
} }
if (par_->nrows() > 1) if (cursor_.par_->nrows() > 1)
par_->delRow(row()); cursor_.par_->delRow(row());
} }
@ -451,9 +450,9 @@ bool MathCursor::Up(bool sel)
int idx, cursor; int idx, cursor;
if (p->idxFirstUp(idx, cursor)) { if (p->idxFirstUp(idx, cursor)) {
push(p, true); push(p, true);
par_ = p; cursor_.par_ = p;
idx_ = idx; cursor_.idx_ = idx;
cursor_ = cursor; cursor_.pos_ = cursor;
dump("Up 3"); dump("Up 3");
return true; return true;
} }
@ -463,23 +462,23 @@ bool MathCursor::Up(bool sel)
if (p) { if (p) {
int idx, cursor; int idx, cursor;
if (p->idxLastUp(idx, cursor)) { if (p->idxLastUp(idx, cursor)) {
array().prev(cursor_); array().prev(cursor_.pos_);
push(p, false); push(p, false);
par_ = p; cursor_.par_ = p;
idx_ = idx; cursor_.idx_ = idx;
cursor_ = cursor; cursor_.pos_ = cursor;
dump("Up 4"); dump("Up 4");
return true; return true;
} }
} }
int x = xarray().pos2x(cursor_); int x = xarray().pos2x(cursor_.pos_);
bool result = par_->idxUp(idx_, cursor_); bool result = cursor_.par_->idxUp(cursor_.idx_, cursor_.pos_);
if (!result && pop()) { if (!result && pop()) {
result = par_->idxUp(idx_, cursor_); result = cursor_.par_->idxUp(cursor_.idx_, cursor_.pos_);
} }
cursor_ = xarray().x2pos(x); cursor_.pos_ = xarray().x2pos(x);
dump("Up 2"); dump("Up 2");
return result; return result;
@ -496,11 +495,11 @@ bool MathCursor::Down(bool sel)
// check whether we could move into an inset on the right or on the left // check whether we could move into an inset on the right or on the left
MathInset * p = nextInset(); MathInset * p = nextInset();
if (p) { if (p) {
int idx, cursor; int idx, pos;
if (p->idxFirstDown(idx, cursor)) { if (p->idxFirstDown(idx, pos)) {
push(p, true); push(p, true);
idx_ = idx; cursor_.idx_ = idx;
cursor_ = cursor; cursor_.pos_ = pos;
dump("Down 3"); dump("Down 3");
return true; return true;
} }
@ -508,23 +507,23 @@ bool MathCursor::Down(bool sel)
p = prevInset(); p = prevInset();
if (p) { if (p) {
int idx, cursor; int idx, pos;
if (p->idxLastDown(idx, cursor)) { if (p->idxLastDown(idx, pos)) {
array().prev(cursor_); array().prev(cursor_.pos_);
push(p, false); push(p, false);
idx_ = idx; cursor_.idx_ = idx;
cursor_ = cursor; cursor_.pos_ = pos;
dump("Down 4"); dump("Down 4");
return true; return true;
} }
} }
int x = xarray().pos2x(cursor_); int x = xarray().pos2x(cursor_.pos_);
bool result = par_->idxDown(idx_, cursor_); bool result = cursor_.par_->idxDown(cursor_.idx_, cursor_.pos_);
if (!result && pop()) { if (!result && pop())
result = par_->idxDown(idx_, cursor_); result = cursor_.par_->idxDown(cursor_.idx_, cursor_.pos_);
}
cursor_ = xarray().x2pos(x); cursor_.pos_ = xarray().x2pos(x);
dump("Down 2"); dump("Down 2");
return result; return result;
@ -544,7 +543,7 @@ bool MathCursor::toggleLimits()
void MathCursor::SetSize(MathStyles size) void MathCursor::SetSize(MathStyles size)
{ {
par_->UserSetSize(size); cursor_.par_->UserSetSize(size);
} }
@ -559,11 +558,11 @@ in_word_set(s) << " \n";
if (!p) { if (!p) {
p = new MathScriptInset(true, false); p = new MathScriptInset(true, false);
insert(p); insert(p);
array().prev(cursor_); array().prev(cursor_.pos_);
} }
push(p, true); push(p, true);
p->up(true); p->up(true);
idx_ = 0; cursor_.idx_ = 0;
return; return;
} }
@ -572,11 +571,11 @@ in_word_set(s) << " \n";
if (!p) { if (!p) {
p = new MathScriptInset(false, true); p = new MathScriptInset(false, true);
insert(p); insert(p);
array().prev(cursor_); array().prev(cursor_.pos_);
} }
push(p, true); push(p, true);
p->down(true); p->down(true);
idx_ = 1; cursor_.idx_ = 1;
return; return;
} }
@ -667,7 +666,7 @@ in_word_set(s) << " \n";
SelCut(); SelCut();
insert(p); insert(p);
if (p->nargs()) { if (p->nargs()) {
array().prev(cursor_); array().prev(cursor_.pos_);
push(p, true); push(p, true);
if (oldsel) if (oldsel)
SelPaste(); SelPaste();
@ -705,7 +704,7 @@ void MathCursor::MacroModeClose()
imacro->SetName(l->name); imacro->SetName(l->name);
} else { } else {
Left(); Left();
array().erase(cursor_); array().erase(cursor_.pos_);
if (l || MathMacroTable::hasTemplate(imacro->name())) if (l || MathMacroTable::hasTemplate(imacro->name()))
Interpret(imacro->name()); Interpret(imacro->name());
imacro->SetName(string()); imacro->SetName(string());
@ -719,8 +718,8 @@ void MathCursor::SelCopy()
{ {
seldump("SelCopy"); seldump("SelCopy");
if (selection) { if (selection) {
int const p1 = min(cursor_, anchor_); int const p1 = min(cursor_.pos_, anchor_.pos_);
int const p2 = max(cursor_, anchor_); int const p2 = max(cursor_.pos_, anchor_.pos_);
selarray = array(); selarray = array();
selarray.erase(p2, selarray.size()); selarray.erase(p2, selarray.size());
selarray.erase(0, p1); selarray.erase(0, p1);
@ -732,9 +731,9 @@ void MathCursor::SelCut()
{ {
seldump("SelCut"); seldump("SelCut");
if (selection) { if (selection) {
int const p1 = min(cursor_, anchor_); int const p1 = min(cursor_.pos_, anchor_.pos_);
int const p2 = max(cursor_, anchor_); int const p2 = max(cursor_.pos_, anchor_.pos_);
cursor_ = p1; // move cursor to a same position cursor_.pos_ = p1; // move cursor to a same position
selarray = array(); selarray = array();
selarray.erase(p2, selarray.size()); selarray.erase(p2, selarray.size());
selarray.erase(0, p1); selarray.erase(0, p1);
@ -748,8 +747,8 @@ void MathCursor::SelDel()
{ {
seldump("SelDel"); seldump("SelDel");
if (selection) { if (selection) {
int const p1 = min(cursor_, anchor_); int const p1 = min(cursor_.pos_, anchor_.pos_);
int const p2 = max(cursor_, anchor_); int const p2 = max(cursor_.pos_, anchor_.pos_);
array().erase(p1, p2); array().erase(p1, p2);
SelClear(); SelClear();
} }
@ -759,8 +758,8 @@ void MathCursor::SelDel()
void MathCursor::SelPaste() void MathCursor::SelPaste()
{ {
seldump("SelPaste"); seldump("SelPaste");
array().insert(cursor_, selarray); array().insert(cursor_.pos_, selarray);
cursor_ += selarray.size(); cursor_.pos_ += selarray.size();
SelClear(); SelClear();
} }
@ -806,13 +805,13 @@ void MathCursor::SelGetArea(int * xpoint, int * ypoint, int & n)
par()->GetXY(xo, yo); par()->GetXY(xo, yo);
int w = par()->width(); int w = par()->width();
// cursor // cursor
int x1 = xarray().xo() + xarray().pos2x(cursor_); int x1 = xarray().xo() + xarray().pos2x(cursor_.pos_);
int y1 = xarray().yo(); int y1 = xarray().yo();
//int a1 = xarray().ascent(); //int a1 = xarray().ascent();
//int d1 = xarray().descent(); //int d1 = xarray().descent();
// anchor // anchor
int x = xarray().xo() + xarray().pos2x(anchor_); int x = xarray().xo() + xarray().pos2x(anchor_.pos_);
int y = xarray().yo(); int y = xarray().yo();
int a = xarray().ascent(); int a = xarray().ascent();
int d = xarray().descent(); int d = xarray().descent();
@ -860,8 +859,8 @@ void MathCursor::SelGetArea(int * xpoint, int * ypoint, int & n)
void MathCursor::handleFont(MathTextCodes t) void MathCursor::handleFont(MathTextCodes t)
{ {
if (selection) { if (selection) {
int const p1 = std::min(cursor_, anchor_); int const p1 = std::min(cursor_.pos_, anchor_.pos_);
int const p2 = std::max(cursor_, anchor_); int const p2 = std::max(cursor_.pos_, anchor_.pos_);
MathArray & ar = array(); MathArray & ar = array();
for (int pos = p1; pos != p2; ar.next(pos)) for (int pos = p1; pos != p2; ar.next(pos))
if (!ar.isInset(pos) && isalnum(ar.GetChar(pos))) { if (!ar.isInset(pos) && isalnum(ar.GetChar(pos))) {
@ -902,26 +901,26 @@ void MathCursor::handleDelim(int l, int r)
void MathCursor::GetPos(int & x, int & y) void MathCursor::GetPos(int & x, int & y)
{ {
x = xarray().xo() + xarray().pos2x(cursor_); x = xarray().xo() + xarray().pos2x(cursor_.pos_);
y = xarray().yo(); y = xarray().yo();
} }
MathTextCodes MathCursor::nextCode() const MathTextCodes MathCursor::nextCode() const
{ {
return array().GetCode(cursor_); return array().GetCode(cursor_.pos_);
} }
MathTextCodes MathCursor::prevCode() const MathTextCodes MathCursor::prevCode() const
{ {
return array().GetCode(cursor_ - 1); return array().GetCode(cursor_.pos_ - 1);
} }
MathInset * MathCursor::par() const MathInset * MathCursor::par() const
{ {
return par_; return cursor_.par_;
} }
@ -933,7 +932,7 @@ InsetFormulaBase const * MathCursor::formula()
int MathCursor::pos() const int MathCursor::pos() const
{ {
return cursor_; return cursor_.pos_;
} }
@ -969,10 +968,10 @@ MathTextCodes MathCursor::getLastCode() const
MathInset * MathCursor::enclosing(MathInsetTypes t, int & idx) const MathInset * MathCursor::enclosing(MathInsetTypes t, int & idx) const
{ {
if (par_->GetType() == t) { if (cursor_.par_->GetType() == t) {
//lyxerr << "enclosing par is current\n"; //lyxerr << "enclosing par is current\n";
idx = idx_; idx = cursor_.idx_;
return par_; return cursor_.par_;
} }
for (int i = path_.size() - 1; i >= 0; --i) { for (int i = path_.size() - 1; i >= 0; --i) {
lyxerr << "checking level " << i << "\n"; lyxerr << "checking level " << i << "\n";
@ -991,8 +990,8 @@ void MathCursor::pullArg()
if (!Left()) if (!Left())
return; return;
normalize(); normalize();
array().erase(cursor_); array().erase(cursor_.pos_);
array().insert(cursor_, a); array().insert(cursor_.pos_, a);
} }
@ -1009,34 +1008,34 @@ void MathCursor::normalize() const
#endif #endif
MathCursor * it = const_cast<MathCursor *>(this); MathCursor * it = const_cast<MathCursor *>(this);
if (idx_ < 0 || idx_ > par_->nargs()) if (cursor_.idx_ < 0 || cursor_.idx_ > cursor_.par_->nargs())
lyxerr << "this should not really happen - 1\n"; lyxerr << "this should not really happen - 1\n";
it->idx_ = max(idx_, 0); it->cursor_.idx_ = max(cursor_.idx_, 0);
it->idx_ = min(idx_, par_->nargs()); it->cursor_.idx_ = min(cursor_.idx_, cursor_.par_->nargs());
if (cursor_ < 0 || cursor_ > array().size()) if (cursor_.pos_ < 0 || cursor_.pos_ > array().size())
lyxerr << "this should not really happen - 2\n"; lyxerr << "this should not really happen - 2\n";
it->cursor_ = max(cursor_, 0); it->cursor_.pos_ = max(cursor_.pos_, 0);
it->cursor_ = min(cursor_, array().size()); it->cursor_.pos_ = min(cursor_.pos_, array().size());
} }
int MathCursor::col() const int MathCursor::col() const
{ {
return par_->col(idx_); return par()->col(cursor_.idx_);
} }
int MathCursor::row() const int MathCursor::row() const
{ {
return par_->row(idx_); return par()->row(cursor_.idx_);
} }
/* /*
char MathIter::GetChar() const char MathIter::GetChar() const
{ {
return array().GetChar(cursor_); return array().GetChar(cursor_.pos_);
} }
@ -1054,7 +1053,7 @@ string MathIter::readString()
MathInset * MathCursor::prevInset() const MathInset * MathCursor::prevInset() const
{ {
normalize(); normalize();
int c = cursor_; int c = cursor_.pos_;
if (!array().prev(c)) if (!array().prev(c))
return 0; return 0;
return array().nextInset(c); return array().nextInset(c);
@ -1064,17 +1063,17 @@ MathInset * MathCursor::prevInset() const
MathInset * MathCursor::nextInset() const MathInset * MathCursor::nextInset() const
{ {
normalize(); normalize();
return array().nextInset(cursor_); return array().nextInset(cursor_.pos_);
} }
MathUpDownInset * MathCursor::nearbyUpDownInset() const MathUpDownInset * MathCursor::nearbyUpDownInset() const
{ {
normalize(); normalize();
MathInset * p = array().prevInset(cursor_); MathInset * p = array().prevInset(cursor_.pos_);
if (p && p->isUpDownInset()) if (p && p->isUpDownInset())
return static_cast<MathUpDownInset *>(p); return static_cast<MathUpDownInset *>(p);
p = array().nextInset(cursor_); p = array().nextInset(cursor_.pos_);
if (p && p->isUpDownInset()) if (p && p->isUpDownInset())
return static_cast<MathUpDownInset *>(p); return static_cast<MathUpDownInset *>(p);
return 0; return 0;
@ -1084,69 +1083,69 @@ MathUpDownInset * MathCursor::nearbyUpDownInset() const
MathArray & MathCursor::array() const MathArray & MathCursor::array() const
{ {
static MathArray dummy; static MathArray dummy;
if (!par_) { if (!cursor_.par_) {
lyxerr << "############ par_ not valid\n"; lyxerr << "############ par_ not valid\n";
return dummy; return dummy;
} }
if (idx_ < 0 || idx_ >= par_->nargs()) { if (cursor_.idx_ < 0 || cursor_.idx_ >= cursor_.par_->nargs()) {
lyxerr << "############ idx_ " << idx_ << " not valid\n"; lyxerr << "############ idx_ " << cursor_.idx_ << " not valid\n";
return dummy; return dummy;
} }
return par_->cell(idx_); return cursor_.par_->cell(cursor_.idx_);
} }
MathXArray & MathCursor::xarray() const MathXArray & MathCursor::xarray() const
{ {
return par_->xcell(idx_); return cursor_.par_->xcell(cursor_.idx_);
} }
bool MathCursor::nextIsInset() const bool MathCursor::nextIsInset() const
{ {
return cursor_ < array().size() && MathIsInset(nextCode()); return cursor_.pos_ < array().size() && MathIsInset(nextCode());
} }
bool MathCursor::prevIsInset() const bool MathCursor::prevIsInset() const
{ {
return cursor_ > 0 && MathIsInset(prevCode()); return cursor_.pos_ > 0 && MathIsInset(prevCode());
} }
int MathCursor::xpos() const int MathCursor::xpos() const
{ {
normalize(); normalize();
return xarray().pos2x(cursor_); return xarray().pos2x(cursor_.pos_);
} }
void MathCursor::gotoX(int x) void MathCursor::gotoX(int x)
{ {
cursor_ = xarray().x2pos(x); cursor_.pos_ = xarray().x2pos(x);
} }
void MathCursor::idxNext() void MathCursor::idxNext()
{ {
par_->idxNext(idx_, cursor_); cursor_.par_->idxNext(cursor_.idx_, cursor_.pos_);
} }
void MathCursor::idxPrev() void MathCursor::idxPrev()
{ {
par_->idxPrev(idx_, cursor_); cursor_.par_->idxPrev(cursor_.idx_, cursor_.pos_);
} }
void MathCursor::splitCell() void MathCursor::splitCell()
{ {
if (idx_ == par_->nargs() - 1) if (cursor_.idx_ == cursor_.par_->nargs() - 1)
return; return;
MathArray ar = array(); MathArray ar = array();
ar.erase(0, cursor_); ar.erase(0, cursor_.pos_);
array().erase(cursor_, array().size()); array().erase(cursor_.pos_, array().size());
++idx_; ++cursor_.idx_;
cursor_ = 0; cursor_.pos_ = 0;
array().insert(0, ar); array().insert(0, ar);
} }
@ -1156,8 +1155,8 @@ void MathCursor::breakLine()
if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION) { if (p->GetType() == LM_OT_SIMPLE || p->GetType() == LM_OT_EQUATION) {
p->mutate(LM_OT_EQNARRAY); p->mutate(LM_OT_EQNARRAY);
p->addRow(row()); p->addRow(row());
idx_ = p->nrows(); cursor_.idx_ = p->nrows();
cursor_ = 0; cursor_.pos_ = 0;
} else { } else {
p->addRow(row()); p->addRow(row());
@ -1172,7 +1171,7 @@ void MathCursor::breakLine()
// split cell // split cell
splitCell(); splitCell();
p->cell(idx_).swap(p->cell(idx_ + p->ncols() - 1)); p->cell(cursor_.idx_).swap(p->cell(cursor_.idx_ + p->ncols() - 1));
} }
} }

View File

@ -126,7 +126,7 @@ public:
/// ///
MathTextCodes getLastCode() const; MathTextCodes getLastCode() const;
/// ///
int idx() const { return idx_; } int idx() const { return cursor_.idx_; }
/// ///
void idxNext(); void idxNext();
/// ///
@ -153,16 +153,9 @@ public:
bool macro_mode; bool macro_mode;
// Selection stuff // Selection stuff
/// /// do we currently select
bool selection; bool selection;
///
int anchor_;
///
int cursor_;
///
int idx_;
///
MathInset * par_;
/// ///
InsetFormulaBase * const formula_; InsetFormulaBase * const formula_;
/// ///
@ -186,14 +179,25 @@ public:
private: private:
/// Description of a position /// Description of a position
struct MathIter { struct MathIter {
/// inset
MathInset * par_; MathInset * par_;
/// cell inset
int idx_; int idx_;
int cursor_; ///
int pos_;
}; };
/// MathPath /// path of positions the cursor had to go if it were leving each inset
std::vector<MathIter> path_; std::vector<MathIter> path_;
/// reference to the last item of the path
MathIter anchor_;
///
MathIter cursor_;
///
int path_idx_;
/// ///
int last() const; int last() const;
/// ///