]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathGrid.cpp
Simplification
[lyx.git] / src / mathed / InsetMathGrid.cpp
index 9c0dca300bfff57e1133a026a8758a5e73f89625..3de72abcb194cd9dedb022fc108871d345a0977a 100644 (file)
@@ -1634,8 +1634,8 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
                        for (row_type r = 0; r < numrows; ++r) {
                                for (col_type c = 0; c < numcols; ++c) {
                                        idx_type i = index(r + startrow, c + startcol);
-                                       cell(i).insert(c == 0 ? cur.pos() : 0,
-                                                      grid.cell(grid.index(r, c)));
+                                       pos_type const ipos = min(cur.pos(), pos_type(cell(i).size()));
+                                       cell(i).insert(ipos, grid.cell(grid.index(r, c)));
                                }
                                if (hline_enabled)
                                        rowinfo_[r].lines += grid.rowinfo_[r].lines;
@@ -1649,7 +1649,7 @@ 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 + startcol);
-                                       idx_type i = index(r + startrow, 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 {