From: Enrico Forestieri Date: Sun, 4 Jul 2010 16:31:53 +0000 (+0000) Subject: Fix bug #6595: empty last row of matrix or eqnarray vanishes. X-Git-Tag: 2.0.0~3069 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=9536afe74261975b916e4e8d9d05c24bdbe4a977;p=lyx.git Fix bug #6595: empty last row of matrix or eqnarray vanishes. This patch essentially reverts r30795 and also provides the correct fix for #2969. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34751 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 900d37abc5..ad7b1140a4 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -644,7 +644,7 @@ void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype) } -docstring InsetMathGrid::eolString(row_type row, bool fragile) const +docstring InsetMathGrid::eolString(row_type row, bool fragile, bool last_eoln) const { docstring eol; @@ -662,7 +662,7 @@ docstring InsetMathGrid::eolString(row_type row, bool fragile) const } // only add \\ if necessary - if (eol.empty() && row + 1 == nrows()) + if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln)) return docstring(); return (fragile ? "\\protect\\\\" : "\\\\") + eol; @@ -1045,19 +1045,23 @@ void InsetMathGrid::write(WriteStream & os, // unless there are vertical lines col_type lastcol = 0; bool emptyline = true; - for (col_type col = beg_col; col < end_col; ++col) - if (!cell(index(row, col)).empty() - || colinfo_[col + 1].lines_) { + bool last_eoln = true; + for (col_type col = beg_col; col < end_col; ++col) { + bool const empty_cell = cell(index(row, col)).empty(); + if (!empty_cell) + last_eoln = false; + if (!empty_cell || colinfo_[col + 1].lines_) { lastcol = col + 1; emptyline = false; } + } for (col_type col = beg_col; col < lastcol; ++col) { os << cell(index(row, col)); if (os.pendingBrace()) ModeSpecifier specifier(os, TEXT_MODE); os << eocString(col, lastcol); } - eol = eolString(row, os.fragile()); + eol = eolString(row, os.fragile(), last_eoln); os << eol; // append newline only if line wasn't completely empty // and the formula is not written on a single line diff --git a/src/mathed/InsetMathGrid.h b/src/mathed/InsetMathGrid.h index efb2fcc236..0dff138b37 100644 --- a/src/mathed/InsetMathGrid.h +++ b/src/mathed/InsetMathGrid.h @@ -240,7 +240,7 @@ protected: /// returns y offset of cell compared to inset int cellYOffset(idx_type idx) const; /// returns proper 'end of line' code for LaTeX - virtual docstring eolString(row_type row, bool fragile) const; + virtual docstring eolString(row_type row, bool fragile, bool last_eoln) const; /// returns proper 'end of column' code for LaTeX virtual docstring eocString(col_type col, col_type lastcol) const; /// splits cells and shifts right part to the next cell diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index dd2b7fea91..d6dbce83f1 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -1122,7 +1122,7 @@ void InsetMathHull::mutate(HullType newtype) } -docstring InsetMathHull::eolString(row_type row, bool fragile) const +docstring InsetMathHull::eolString(row_type row, bool fragile, bool last_eoln) const { docstring res; if (numberedType()) { @@ -1132,7 +1132,9 @@ docstring InsetMathHull::eolString(row_type row, bool fragile) const if (nonum_[row] && (type_ != hullMultline)) res += "\\nonumber "; } - return res + InsetMathGrid::eolString(row, fragile); + // Never add \\ on the last empty line of eqnarray and friends + last_eoln = false; + return res + InsetMathGrid::eolString(row, fragile, last_eoln); } diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index 945e0f8a51..08e3a03cba 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -165,7 +165,7 @@ protected: bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & status) const; /// - docstring eolString(row_type row, bool fragile) const; + docstring eolString(row_type row, bool fragile, bool last_eoln) const; private: virtual Inset * clone() const; diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 90d7c9349a..a8213959b8 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -1244,7 +1244,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // probably need to refine this test. // Right now we only have to test for // single line hull insets. - if (grid.nrows() > 1) + if (grid.nrows() > 1 && name == "array") delEmptyLastRow(grid); return success_; }