]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathGrid.cpp
Revert "DocBook: make openParTag/closeTag use paragraphs instead of layouts."
[lyx.git] / src / mathed / InsetMathGrid.cpp
index f4e868ec83d7f0c9d5512471d17a1bee40fafdef..0a637ec715c26ae8f32d5bf4ab5f718de9d02385 100644 (file)
@@ -1624,7 +1624,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                } else {
                        // multiple cells
                        cur.recordUndoInset();
-                       col_type startcol =  col(cur.idx());
+                       col_type startcol = col(cur.idx());
                        row_type startrow = cur.row();
                        col_type oldncols = ncols();
                        col_type numcols =
@@ -1648,8 +1648,8 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                                }
                                // append columns for the left over horizontal cells
                                for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c) {
-                                       addCol(c + 1);
-                                       idx_type i = index(r + startrow, c + 1);
+                                       addCol(c + startcol);
+                                       idx_type i = index(r + startrow, min(c + startcol, ncols() - 1));
                                        cell(i).append(grid.cell(grid.index(r, c)));
                                        ++numcols;
                                }
@@ -1662,7 +1662,7 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                                row_type crow = startrow + r;
                                addRow(crow - 1);
                                for (col_type c = 0; c < grid.ncols(); ++c)
-                                       cell(index(crow, c + startcol)).append(grid.cell(grid.index(r, c)));
+                                       cell(index(min(crow, nrows() - 1), min(c + startcol, ncols() - 1))).append(grid.cell(grid.index(r, c)));
                                if (hline_enabled)
                                        rowinfo_[crow].lines += grid.rowinfo_[r].lines;
                                else {