]> git.lyx.org Git - features.git/commitdiff
Fix bug #6595: empty last row of matrix or eqnarray vanishes.
authorEnrico Forestieri <forenr@lyx.org>
Sun, 4 Jul 2010 16:31:53 +0000 (16:31 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 4 Jul 2010 16:31:53 +0000 (16:31 +0000)
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

src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathGrid.h
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathHull.h
src/mathed/MathParser.cpp

index 900d37abc5bebb3a536b69439f4102726897e473..ad7b1140a4640cc398cc61546748dc40822ea919 100644 (file)
@@ -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
index efb2fcc236ca44c661ebfa3bcb89a5c5c036632b..0dff138b3722101bdd43fce2e43aac4869486493 100644 (file)
@@ -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
index dd2b7fea911fd18facecd45bb049f5c030e643f3..d6dbce83f164de47ac5a9cb32b0d51aec40a0d6a 100644 (file)
@@ -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);
 }
 
 
index 945e0f8a515afea8a2a5e99952efb1b2143c0a8b..08e3a03cba0b9820bd9ba4ddf02033abed52db22 100644 (file)
@@ -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;
index 90d7c9349a8076aacdbd77c3e8e016d97dcaec7e..a8213959b87208bddf29c59d2acc5677e20b22ae 100644 (file)
@@ -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_;
                                }