Erase correctly math multi-cell selection

What a selection spans several cells in mathed, and a deletion occurs though LFUN_CHAR_DELETE_FORWARD for example, only the case of a proper grid was handled. When no such grid exists, all cells between the first and the last index are cleared now.
This commit is contained in:
Jean-Marc Lasgouttes 2014-10-16 16:16:15 +02:00
parent ac018bd8db
commit f58d9f27a2

View File

@ -1254,17 +1254,22 @@ void eraseSelection(Cursor & cur)
//lyxerr << "cap::eraseSelection begin: " << cur << endl; //lyxerr << "cap::eraseSelection begin: " << cur << endl;
CursorSlice const & i1 = cur.selBegin(); CursorSlice const & i1 = cur.selBegin();
CursorSlice const & i2 = cur.selEnd(); CursorSlice const & i2 = cur.selEnd();
if (i1.inset().asInsetMath()) { if (!i1.asInsetMath()) {
LYXERR0("Can't erase this selection");
return;
}
saveSelection(cur); saveSelection(cur);
cur.top() = i1; cur.top() = i1;
InsetMath * p = i1.asInsetMath();
if (i1.idx() == i2.idx()) { if (i1.idx() == i2.idx()) {
i1.cell().erase(i1.pos(), i2.pos()); i1.cell().erase(i1.pos(), i2.pos());
// We may have deleted i1.cell(cur.pos()). // We may have deleted i1.cell(cur.pos()).
// Make sure that pos is valid. // Make sure that pos is valid.
if (cur.pos() > cur.lastpos()) if (cur.pos() > cur.lastpos())
cur.pos() = cur.lastpos(); cur.pos() = cur.lastpos();
} else { } else if (p->nrows() > 0 && p->ncols() > 0) {
InsetMath * p = i1.asInsetMath(); // This is a grid, delete a nice square region
Inset::row_type r1, r2; Inset::row_type r1, r2;
Inset::col_type c1, c2; Inset::col_type c1, c2;
region(i1, i2, r1, r2, c1, c2); region(i1, i2, r1, r2, c1, c2);
@ -1273,12 +1278,19 @@ void eraseSelection(Cursor & cur)
p->cell(p->index(row, col)).clear(); p->cell(p->index(row, col)).clear();
// We've deleted the whole cell. Only pos 0 is valid. // We've deleted the whole cell. Only pos 0 is valid.
cur.pos() = 0; cur.pos() = 0;
} else {
Inset::idx_type idx1 = i1.idx();
Inset::idx_type idx2 = i2.idx();
if (idx1 > idx2)
swap(idx1, idx2);
for (Inset::idx_type idx = idx1 ; idx <= idx2; ++idx)
p->cell(idx).clear();
// We've deleted the whole cell. Only pos 0 is valid.
cur.pos() = 0;
} }
// need a valid cursor. (Lgb) // need a valid cursor. (Lgb)
cur.clearSelection(); cur.clearSelection();
} else {
lyxerr << "can't erase this selection 1" << endl;
}
//lyxerr << "cap::eraseSelection end: " << cur << endl; //lyxerr << "cap::eraseSelection end: " << cur << endl;
} }