]> git.lyx.org Git - features.git/commitdiff
Fix a leak; cosmetics
authorAndré Pönitz <poenitz@gmx.net>
Tue, 7 Aug 2001 12:02:21 +0000 (12:02 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 7 Aug 2001 12:02:21 +0000 (12:02 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2439 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/array.C
src/mathed/array.h
src/mathed/math_cursor.C
src/mathed/math_matrixinset.C

index a42580f17af8ee48f933cc4a783d2278264bca1e..db18ed90bba31def5ec94dced0812969ecf172c4 100644 (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
 {
        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);
 }
 
index 836bc7402927b91034404edb5212b8e0d0486fb9..46a69578d4d9e30b803e02f2b425f86e7eff144a 100644 (file)
@@ -76,8 +76,6 @@ public:
        ///
        void erase();
        ///
-       bool next(int & pos) const;
-       ///
        int last() const;
 
 
index a6bb45d1f51ed9e5bc7d058d636146279d3f83e8..fccacf90b2465b8739d3ea76fbb85d5a843383f4 100644 (file)
@@ -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";
index bb830b8e42e55d911f06aaaa3a915800930de743..81a4b064831b5e5cbd8bdc99917fdd6c8c2e166d 100644 (file)
@@ -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);