+ //lyxerr << "LCursor::eraseSelection begin: " << cur << endl;
+ CursorSlice const & i1 = cur.selBegin();
+ CursorSlice const & i2 = cur.selEnd();
+ if (i1.inset().asInsetMath()) {
+ cur.top() = i1;
+ if (i1.idx() == i2.idx()) {
+ i1.cell().erase(i1.pos(), i2.pos());
+ // We may have deleted i1.cell(cur.pos()).
+ // Make sure that pos is valid.
+ if (cur.pos() > cur.lastpos())
+ cur.pos() = cur.lastpos();
+ } else {
+ InsetMath * p = i1.asInsetMath();
+ InsetBase::row_type r1, r2;
+ InsetBase::col_type c1, c2;
+ region(i1, i2, r1, r2, c1, c2);
+ for (InsetBase::row_type row = r1; row <= r2; ++row)
+ for (InsetBase::col_type col = c1; col <= c2; ++col)
+ p->cell(p->index(row, col)).clear();
+ // We've deleted the whole cell. Only pos 0 is valid.
+ cur.pos() = 0;
+ }
+ // need a valid cursor. (Lgb)
+ cur.clearSelection();
+ } else {
+ lyxerr << "can't erase this selection 1" << endl;
+ }
+ //lyxerr << "LCursor::eraseSelection end: " << cur << endl;
+}
+
+
+void selDel(LCursor & cur)
+{
+ //lyxerr << "LCursor::selDel" << endl;
+ if (cur.selection())
+ eraseSelection(cur);
+}
+
+
+void selClearOrDel(LCursor & cur)
+{
+ //lyxerr << "LCursor::selClearOrDel" << endl;
+ if (lyxrc.auto_region_delete)
+ selDel(cur);
+ else
+ cur.selection() = false;
+}
+
+
+docstring grabSelection(LCursor const & cur)
+{
+ if (!cur.selection())
+ return docstring();
+
+ // FIXME: What is wrong with the following?
+#if 0
+ std::ostringstream os;
+ for (DocIterator dit = cur.selectionBegin();
+ dit != cur.selectionEnd(); dit.forwardPos())
+ os << asString(dit.cell());
+ return os.str();
+#endif
+
+ CursorSlice i1 = cur.selBegin();
+ CursorSlice i2 = cur.selEnd();
+
+ if (i1.idx() == i2.idx()) {
+ if (i1.inset().asInsetMath()) {
+ MathArray::const_iterator it = i1.cell().begin();
+ return asString(MathArray(it + i1.pos(), it + i2.pos()));
+ } else {
+ return from_ascii("unknown selection 1");
+ }
+ }
+
+ InsetBase::row_type r1, r2;
+ InsetBase::col_type c1, c2;
+ region(i1, i2, r1, r2, c1, c2);
+
+ docstring data;
+ if (i1.inset().asInsetMath()) {
+ for (InsetBase::row_type row = r1; row <= r2; ++row) {
+ if (row > r1)
+ data += "\\\\";
+ for (InsetBase::col_type col = c1; col <= c2; ++col) {
+ if (col > c1)
+ data += '&';
+ data += asString(i1.asInsetMath()->
+ cell(i1.asInsetMath()->index(row, col)));
+ }
+ }
+ } else {
+ data = from_ascii("unknown selection 2");
+ }
+ return data;
+}
+
+
+void dirtyTabularStack(bool b)
+{
+ dirty_tabular_stack_ = b;
+}