Fix a leak; cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2439 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-08-07 12:02:21 +00:00
parent fb2300f658
commit 089f4fca7d
4 changed files with 34 additions and 43 deletions

View File

@ -46,16 +46,6 @@ void MathArray::deep_copy(int pos1, int pos2)
} }
bool MathArray::next(int & pos) const
{
if (pos >= size() - 1)
return false;
++pos;
return true;
}
int MathArray::last() const int MathArray::last() const
{ {
return size() - 1; return size() - 1;
@ -107,7 +97,7 @@ string MathArray::getString(int & pos) const
MathTextCodes const fcode = getCode(pos); MathTextCodes const fcode = getCode(pos);
do { do {
s += getChar(pos); s += getChar(pos);
next(pos); ++pos;
} while (pos < size() && !isInset(pos) && getCode(pos) == fcode); } while (pos < size() && !isInset(pos) && getCode(pos) == fcode);
return s; return s;
@ -198,14 +188,14 @@ void MathArray::erase()
void MathArray::erase(int pos) void MathArray::erase(int pos)
{ {
if (pos < size()) if (pos < size())
bf_.erase(bf_.begin() + pos); erase(pos, pos + 1);
} }
void MathArray::erase(int pos1, int pos2) void MathArray::erase(int pos1, int pos2)
{ {
for (int pos = pos1; pos < pos2; ++pos) for (int pos = pos1; pos < pos2; ++pos)
delete nextInset(pos); delete bf_[pos];
bf_.erase(bf_.begin() + pos1, bf_.begin() + pos2); bf_.erase(bf_.begin() + pos1, bf_.begin() + pos2);
} }

View File

@ -76,8 +76,6 @@ public:
/// ///
void erase(); void erase();
/// ///
bool next(int & pos) const;
///
int last() const; int last() const;

View File

@ -210,6 +210,7 @@ bool MathCursor::openable(MathInset * p, bool sel, bool useupdown) const
{ {
if (!p) if (!p)
return false; return false;
if (!(p->isActive() || (useupdown && p->isScriptInset()))) if (!(p->isActive() || (useupdown && p->isScriptInset())))
return false; return false;
@ -230,6 +231,12 @@ void MathCursor::plainLeft()
} }
void MathCursor::plainRight()
{
++cursor().pos_;
}
bool MathCursor::left(bool sel) bool MathCursor::left(bool sel)
{ {
dump("Left 1"); dump("Left 1");
@ -263,12 +270,6 @@ bool MathCursor::left(bool sel)
} }
void MathCursor::plainRight()
{
++cursor().pos_;
}
bool MathCursor::right(bool sel) bool MathCursor::right(bool sel)
{ {
dump("Right 1"); dump("Right 1");
@ -284,14 +285,18 @@ bool MathCursor::right(bool sel)
push(p, true); push(p, true);
return true; return true;
} }
if (array().next(cursor().pos_)) if (cursor().pos_ != array().size()) {
plainRight();
return true; return true;
if (cursor().par_->idxRight(cursor().idx_, cursor().pos_)) }
if (cursor().par_->idxRight(cursor().idx_, cursor().pos_)) {
return true; return true;
if (!pop()) }
return false; if (pop()) {
array().next(cursor().pos_); plainRight();
return true; return true;
}
return false;
} }
@ -450,7 +455,7 @@ void MathCursor::erase()
} }
// delete empty cells if necessary // delete empty cells if necessary
if (cursor().pos_ == 0 && array().size() == 0) { if (cursor().pos_ == 0 && array().empty()) {
bool popit; bool popit;
bool removeit; bool removeit;
cursor().par_->idxDelete(cursor().idx_, popit, removeit); cursor().par_->idxDelete(cursor().idx_, popit, removeit);
@ -721,15 +726,12 @@ void MathCursor::interpret(string const & s)
} }
if (p) { if (p) {
bool oldsel = selection_; selCut();
if (oldsel)
selCut();
insert(p); insert(p);
if (p->nargs()) { if (p->nargs()) {
plainLeft(); plainLeft();
right(); // do not push for e.g. MathSymbolInset right(); // do not push for e.g. MathSymbolInset
if (oldsel) selPaste();
selPaste();
} }
p->metrics(p->size()); p->metrics(p->size());
} }
@ -776,8 +778,8 @@ void MathCursor::selCut()
if (selection_) { if (selection_) {
theSelection.grab(*this); theSelection.grab(*this);
theSelection.erase(*this); theSelection.erase(*this);
selClear();
} }
selClear();
} }
@ -1282,7 +1284,7 @@ MathCursorPos MathCursor::normalAnchor() const
MathCursorPos normal = Anchor_[Cursor_.size() - 1]; MathCursorPos normal = Anchor_[Cursor_.size() - 1];
if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) { if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) {
// anchor is behind cursor -> move anchor behind the inset // anchor is behind cursor -> move anchor behind the inset
normal.cell().next(normal.pos_); ++normal.pos_;
} }
//lyxerr << "normalizing: from " << Anchor_[Anchor_.size() - 1] << " to " //lyxerr << "normalizing: from " << Anchor_[Anchor_.size() - 1] << " to "
// << normal << "\n"; // << normal << "\n";

View File

@ -465,15 +465,16 @@ void MathMatrixInset::mutate(short newtype)
MathGridInset::addCol(1); MathGridInset::addCol(1);
// split it "nicely" on the firest relop // split it "nicely" on the firest relop
int pos1 = firstRelOp(cell(0)); int pos = firstRelOp(cell(0));
cell(1) = cell(0); cell(1) = cell(0);
cell(0).erase(pos1, cell(0).size()); cell(0).erase(pos, cell(0).size());
cell(1).erase(0, pos1); cell(1).erase(0, pos);
int pos2 = 0;
cell(1).next(pos2); if (cell(1).size()) {
cell(2) = cell(1); cell(2) = cell(1);
cell(1).erase(pos2, cell(1).size()); cell(1).erase(1, cell(1).size());
cell(2).erase(0, pos2); cell(2).erase(0);
}
halign("rcl"); halign("rcl");
setType(LM_OT_EQNARRAY); setType(LM_OT_EQNARRAY);