From 62818cea01a44a7c592b3475f5760064ccf324f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 27 Nov 2001 09:44:32 +0000 Subject: [PATCH] fix crash discovered by Michael git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3085 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_cursor.C | 4 ++-- src/mathed/math_gridinset.C | 38 +++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index dfcca46357..afc6bbc179 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -952,7 +952,7 @@ void MathCursor::normalize() const << idx() << " " << par()->nargs() << "\n"; dump("error 2"); } - it->idx() = min(idx(), par()->nargs() - 1); + it->idx() = min(idx(), par()->nargs() - 1); if (pos() > size()) { lyxerr << "this should not really happen - 2: " @@ -1058,7 +1058,7 @@ void MathCursor::idxPrev() void MathCursor::splitCell() { - if (idx() == par()->nargs() - 1) + if (idx() + 1 == par()->nargs()) return; MathArray ar = array(); ar.erase(0, pos()); diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index fea6255d2d..600b7140cc 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -403,7 +403,7 @@ bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const { // leave matrix if on the right hand edge - if (col(idx) == ncols() - 1) + if (col(idx) + 1 == ncols()) return false; idx++; pos = 0; @@ -490,30 +490,26 @@ void MathGridInset::idxDelete(idx_type & idx, bool & popit, bool & deleteit) popit = false; deleteit = false; - // delete entire sequence of ncols() empty cells if possible - if (idx <= index(nrows() - 1, 0)) { - bool deleterow = true; - for (idx_type i = idx; i < idx + ncols(); ++i) - if (cell(i).size()) { - deleterow = false; - break; - } + // nothing to do if we are in the last row of the inset + if (row(idx) + 1 == nrows()) + return; - if (deleterow) { - // move cells if necessary - for (idx_type i = index(row(idx), 0); i < idx; ++i) - cell(i).swap(cell(i + ncols())); - - delRow(row(idx)); - - if (idx >= nargs()) - idx = nargs() - 1; + // try to delete entire sequence of ncols() empty cells if possible + for (idx_type i = idx; i < idx + ncols(); ++i) + if (cell(i).size()) return; - } - } + + // move cells if necessary + for (idx_type i = index(row(idx), 0); i < idx; ++i) + cell(i).swap(cell(i + ncols())); + + delRow(row(idx)); + + if (idx >= nargs()) + idx = nargs() - 1; // undo effect of Ctrl-Tab (i.e. pull next cell) - //if (idx != nargs() - 1) + //if (idx + 1 != nargs()) // cell(idx).swap(cell(idx + 1)); }