X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathGrid.cpp;h=0a637ec715c26ae8f32d5bf4ab5f718de9d02385;hb=21c92c8a129b5f3ff56de33bf2941a25967cffbb;hp=b6d90eed16b9a2081fe5d60cbc686478fb0ffe13;hpb=acc3f2cef861772a4b2b4b30bcde98daff0d2bc6;p=lyx.git diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index b6d90eed16..0a637ec715 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -1184,15 +1184,15 @@ void InsetMathGrid::normalize(NormalStream & os) const } -void InsetMathGrid::mathmlize(MathStream & os) const +void InsetMathGrid::mathmlize(MathStream & ms) const { bool const havetable = nrows() > 1 || ncols() > 1; if (havetable) - os << MTag("mtable"); + ms << MTag("mtable"); char const * const celltag = havetable ? "mtd" : "mrow"; for (row_type row = 0; row < nrows(); ++row) { if (havetable) - os << MTag("mtr"); + ms << MTag("mtr"); for (col_type col = 0; col < ncols(); ++col) { idx_type const i = index(row, col); if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) { @@ -1200,16 +1200,16 @@ void InsetMathGrid::mathmlize(MathStream & os) const ostringstream attr; if (havetable && cellcols > 1) attr << "colspan='" << cellcols << '\''; - os << MTag(celltag, attr.str()); - os << cell(index(row, col)); - os << ETag(celltag); + ms << MTag(celltag, attr.str()); + ms << cell(index(row, col)); + ms << ETag(celltag); } } if (havetable) - os << ETag("mtr"); + ms << ETag("mtr"); } if (havetable) - os << ETag("mtable"); + ms << ETag("mtable"); } @@ -1624,13 +1624,16 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) } else { // multiple cells cur.recordUndoInset(); - col_type const numcols = - min(grid.ncols(), ncols() - col(cur.idx())); + col_type startcol = col(cur.idx()); + row_type startrow = cur.row(); + col_type oldncols = ncols(); + col_type numcols = + min(grid.ncols(), ncols() - startcol); row_type const numrows = min(grid.nrows(), nrows() - cur.row()); for (row_type r = 0; r < numrows; ++r) { for (col_type c = 0; c < numcols; ++c) { - idx_type i = index(r + cur.row(), c + col(cur.idx())); + idx_type i = index(r + startrow, c + startcol); cell(i).insert(c == 0 ? cur.pos() : 0, grid.cell(grid.index(r, c))); } @@ -1638,23 +1641,30 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) rowinfo_[r].lines += grid.rowinfo_[r].lines; else { for (unsigned int l = 0; l < grid.rowinfo_[r].lines; ++l) { - idx_type i = index(r + cur.row(), 0); + idx_type i = index(r + startrow, 0); cell(i).insert(0, MathAtom(new InsetMathUnknown(from_ascii("\\hline")))); } } - // append the left over horizontal cells to the last column - idx_type i = index(r + cur.row(), ncols() - 1); - for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c) + // 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, min(c + startcol, ncols() - 1)); cell(i).append(grid.cell(grid.index(r, c))); + ++numcols; + } } - // append the left over vertical cells to the last _cell_ + // amend cursor position if cols have been appended + cur.idx() += startrow * (ncols() - oldncols); + // append rows for the left over vertical cells idx_type i = nargs() - 1; for (row_type r = numrows; r < grid.nrows(); ++r) { + row_type crow = startrow + r; + addRow(crow - 1); for (col_type c = 0; c < grid.ncols(); ++c) - cell(i).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_[r].lines += grid.rowinfo_[r].lines; + rowinfo_[crow].lines += grid.rowinfo_[r].lines; else { for (unsigned int l = 0; l < grid.rowinfo_[r].lines; ++l) { cell(i).insert(0,