From 089f4fca7d614f9b3830ce9278cb1f29d0df5a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 7 Aug 2001 12:02:21 +0000 Subject: [PATCH] Fix a leak; cosmetics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2439 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/array.C | 16 +++---------- src/mathed/array.h | 2 -- src/mathed/math_cursor.C | 42 ++++++++++++++++++----------------- src/mathed/math_matrixinset.C | 17 +++++++------- 4 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/mathed/array.C b/src/mathed/array.C index a42580f17a..db18ed90bb 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -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 { return size() - 1; @@ -107,7 +97,7 @@ string MathArray::getString(int & pos) const MathTextCodes const fcode = getCode(pos); do { s += getChar(pos); - next(pos); + ++pos; } while (pos < size() && !isInset(pos) && getCode(pos) == fcode); return s; @@ -198,14 +188,14 @@ void MathArray::erase() void MathArray::erase(int pos) { if (pos < size()) - bf_.erase(bf_.begin() + pos); + erase(pos, pos + 1); } void MathArray::erase(int pos1, int pos2) { for (int pos = pos1; pos < pos2; ++pos) - delete nextInset(pos); + delete bf_[pos]; bf_.erase(bf_.begin() + pos1, bf_.begin() + pos2); } diff --git a/src/mathed/array.h b/src/mathed/array.h index 836bc74029..46a69578d4 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -76,8 +76,6 @@ public: /// void erase(); /// - bool next(int & pos) const; - /// int last() const; diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index a6bb45d1f5..fccacf90b2 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -210,6 +210,7 @@ bool MathCursor::openable(MathInset * p, bool sel, bool useupdown) const { if (!p) return false; + if (!(p->isActive() || (useupdown && p->isScriptInset()))) return false; @@ -230,6 +231,12 @@ void MathCursor::plainLeft() } +void MathCursor::plainRight() +{ + ++cursor().pos_; +} + + bool MathCursor::left(bool sel) { dump("Left 1"); @@ -263,12 +270,6 @@ bool MathCursor::left(bool sel) } -void MathCursor::plainRight() -{ - ++cursor().pos_; -} - - bool MathCursor::right(bool sel) { dump("Right 1"); @@ -284,14 +285,18 @@ bool MathCursor::right(bool sel) push(p, true); return true; } - if (array().next(cursor().pos_)) + if (cursor().pos_ != array().size()) { + plainRight(); return true; - if (cursor().par_->idxRight(cursor().idx_, cursor().pos_)) + } + if (cursor().par_->idxRight(cursor().idx_, cursor().pos_)) { return true; - if (!pop()) - return false; - array().next(cursor().pos_); - return true; + } + if (pop()) { + plainRight(); + return true; + } + return false; } @@ -450,7 +455,7 @@ void MathCursor::erase() } // delete empty cells if necessary - if (cursor().pos_ == 0 && array().size() == 0) { + if (cursor().pos_ == 0 && array().empty()) { bool popit; bool removeit; cursor().par_->idxDelete(cursor().idx_, popit, removeit); @@ -721,15 +726,12 @@ void MathCursor::interpret(string const & s) } if (p) { - bool oldsel = selection_; - if (oldsel) - selCut(); + selCut(); insert(p); if (p->nargs()) { plainLeft(); right(); // do not push for e.g. MathSymbolInset - if (oldsel) - selPaste(); + selPaste(); } p->metrics(p->size()); } @@ -776,8 +778,8 @@ void MathCursor::selCut() if (selection_) { theSelection.grab(*this); theSelection.erase(*this); - selClear(); } + selClear(); } @@ -1282,7 +1284,7 @@ MathCursorPos MathCursor::normalAnchor() const MathCursorPos normal = Anchor_[Cursor_.size() - 1]; if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) { // anchor is behind cursor -> move anchor behind the inset - normal.cell().next(normal.pos_); + ++normal.pos_; } //lyxerr << "normalizing: from " << Anchor_[Anchor_.size() - 1] << " to " // << normal << "\n"; diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index bb830b8e42..81a4b06483 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -465,15 +465,16 @@ void MathMatrixInset::mutate(short newtype) MathGridInset::addCol(1); // split it "nicely" on the firest relop - int pos1 = firstRelOp(cell(0)); + int pos = firstRelOp(cell(0)); cell(1) = cell(0); - cell(0).erase(pos1, cell(0).size()); - cell(1).erase(0, pos1); - int pos2 = 0; - cell(1).next(pos2); - cell(2) = cell(1); - cell(1).erase(pos2, cell(1).size()); - cell(2).erase(0, pos2); + cell(0).erase(pos, cell(0).size()); + cell(1).erase(0, pos); + + if (cell(1).size()) { + cell(2) = cell(1); + cell(1).erase(1, cell(1).size()); + cell(2).erase(0); + } halign("rcl"); setType(LM_OT_EQNARRAY);